嘿!我正在尝试用正确的 F# 编写一个 POCO 类……但是出了点问题……
我想“翻译”为正确的 F# 的 C# 代码是:
public class MyTest
{
[Key]
public int ID { get; set; }
public string Name { get; set; }
}
在 F# 中,我最接近上述代码的是:
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
但是,当我尝试访问 F# 版本的属性时,它只会返回一个编译错误说
“基于此程序点之前的信息查找不确定类型的对象。在此程序点之前可能需要类型注释以限制对象的类型。这可能允许解析查找。”
试图获取该属性的代码是我的存储库的一部分(我使用的是 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
这到底是怎么回事?
提前致谢!