POCO を使用する Entity Framework でいくつかの問題が発生しています。私が見ている動作が予想されるものなのか、それともなぜそれが起こっているのかを深く掘り下げる必要があるのかどうか、誰かが大まかなレベルで教えてくれることを願っています.
クラスCustomerと別のCustomerTypeがあるのでCustomer、Type(タイプCustomerTypeを示すタイプの)CustomerTypeプロパティCustomersがあり、s のコレクションであるプロパティがありますCustomer(そのタイプを持つすべてCustomerの s) したがって、これらは基本的に関連付けの両端のナビゲーション プロパティであり、結果として次のようなPOCOコードで:
public partial class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public int TypeId { get; set; }
public CustomerType Type { get; set; }
}
public partial class CustomerType
{
public CustomerType()
{
this.Customers = new HashSet<CustomerType>();
}
public int Id { get; set; }
public string TypeName { get; set; }
public virtual ICollection<Customer> Customers { get; set; }
}
DbContext.Configuration.ProxyCreationEnabled=falseProxy の作成と LazyLoading (つまりとの両方) をオフにしましDbContext.Configuration.LazyLoadingEnabled=falseた。
Customerセットからインスタンスを取得すると、予想どおり、Typeそれらのプロパティはデフォルトで null です。
Customerしかし、セットからインスタンスを取得すると.Include("Type")、プロパティがロードされるだけでなくType、子もロードされます。つまり、Customerこれらのそれぞれの のコレクションです。
これは期待されていますか?