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