DataLoadOptions.AssociateWith Method
.NET Framework 3.5
Filters the objects retrieved for a particular relationship.
This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.
| Name | Description | |
|---|---|---|
|
AssociateWith<T>(Expression<Func<T, Object>>) | Filters objects retrieved for a particular relationship. |
|
AssociateWith(LambdaExpression) | Filters the objects retrieved for a particular relationship. |
In the following example, the AssociateWith method limits the Orders retrieved to those that have not been shipped today. Without this approach, all Orders would have been retrieved even though only a subset is desired.
Northwnd db = new Northwnd(@"c:\northwnd.mdf"); DataLoadOptions dlo = new DataLoadOptions(); dlo.AssociateWith<Customer>(c => c.Orders.Where(p => p.ShippedDate != DateTime.Today)); db.LoadOptions = dlo; var custOrderQuery = from cust in db.Customers where cust.City == "London" select cust; foreach (Customer custObj in custOrderQuery) { Console.WriteLine(custObj.CustomerID); foreach (Order ord in custObj.Orders) { Console.WriteLine("\t {0}",ord.OrderDate); } }