1.主类中包含子类的属性类型用EntitySet<子类>,子类包含主类的属性类型用EntityRef<主类>

2.禁用延迟加载:

 DataContext dbContext = new DataContext();
 dbContext.DeferredLoadingEnabled = false;

并设置加载主类时,同时加载子类集合(需要设置LoadOptions属性):

DataLoadOptions loadoption = new DataLoadOptions();
        loadoption.LoadWith<Customers>(cust => cust.Orders);
        dbContext.LoadOptions = loadoption;

3.

  • 一对一关系:两个类中都是EntityRef
  • 一对多关系:主记录中EntitySet,子记录中EntityRef
  • 多对多关系:分解成两个一对多
  • 自关联:既有EntitySet又有EntityRef

 

相关文章:

  • 2021-12-13
  • 2022-01-07
  • 2021-07-30
  • 2021-07-06
  • 2022-12-23
猜你喜欢
  • 2022-01-16
  • 2021-05-23
  • 2021-08-27
  • 2022-01-03
  • 2021-12-06
  • 2021-08-27
相关资源
相似解决方案