有时我们需要立即加载指定的关联数据。
DataLoadOptions loadOptions = new DataLoadOptions();
loadOptions.LoadWith
<Customer>(it => it.Orders);
DataContext.LoadOptions 
= loadOptions;

DataContext.Log = Console.Out; // 用来查看请求的SQL语句,确定只发送一次请求。
LoadWith会将指定关联的数据全部加载,有时我们需要过滤关联数据怎么办?
使用DataLoadOptions的另一个方法AssociateWith<T>(Expression<Func<T, Object>>)。
DataLoadOptions loadOptions = new DataLoadOptions();
loadOptions.LoadWith
<Customer>(it => it.Orders.Where(o=> o.ShippedDate != DateTime.Today));
DataContext.LoadOptions 
= loadOptions; 

相关文章:

  • 2021-06-12
  • 2021-07-05
  • 2022-02-19
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
猜你喜欢
  • 2021-06-10
  • 2022-12-23
  • 2021-11-25
  • 2022-02-08
  • 2021-08-02
相关资源
相似解决方案