F# - POCO Class

Posted by ebb on Stack Overflow See other posts from Stack Overflow or by ebb
Published on 2010-12-30T20:21:05Z Indexed on 2010/12/30 20:53 UTC
Read the original article Hit count: 229

Filed under:
|
|
|

Hey there! I'm trying to write a POCO class in proper F#... But something is wrong..

The C# code that I want to "translate" to proper F# is:

public class MyTest
{
    [Key]
    public int ID { get; set; }

    public string Name { get; set; }
}

The closest I can come to the above code in F# is something like:

type Mytest() =

let mutable _id : int = 0;
let mutable _name : string = null;

[<KeyAttribute>]
member x.ID
    with public get() : int = _id
and     public set(value) = _id <- value

member x.Name 
    with public get() : string = _name
    and public set value = _name <- value

However when I try to access the properties of the F# version it just returns a compile error saying

"Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved."

The code thats trying to get the property is a part of my Repository (I'm using EF Code First).

module Databasethings =

    let GetEntries =
        let ctx = new SevenContext()
        let mydbset = ctx.Set<MyTest>()
        let entries = mydbset.Select(fun item -> item.Name).ToList() // This line comes up with a compile error at "item.Name" (the compile error is written above)
        entries

What the hell is going on?

Thanks in advance!

© Stack Overflow or respective owner

Related posts about F#

Related posts about POCO