ちょっと、そこ!適切な 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
一体何が起こっているのですか?
前もって感謝します!