您的位置:首页 > 数据库

Linq to sql立即加载

2010-07-13 14:55 232 查看
有时我们需要立即加载指定的关联数据。
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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐