Provides for immediate loading and filtering of related data.
Assembly: System.Data.Linq (in System.Data.Linq.dll)
Filters the objects retrieved for a particular relationship.
|AssociateWith(Of T)(Expression(Of Func(Of T, Object)))|
Filters objects retrieved for a particular relationship.
Determines whether the specified object is equal to the current object.(Inherited from Object.)
Serves as the default hash function. (Inherited from Object.)
Retrieves specified data related to the main target by using a lambda expression.
|LoadWith(Of T)(Expression(Of Func(Of T, Object)))|
Specifies which sub-objects to retrieve when a query is submitted for an object of type T.
Returns a string that represents the current object.(Inherited from Object.)
When you query for an object, you actually retrieve only the object you requested. The related objects are not automatically fetched at the same time. (For more information, see Querying Across Relationships.)
Example 1: Self recursive
dlo.LoadWith<Employee>(e => e.Reports);
Example 2: Back-pointers
dlo.LoadWith <Customer>(c => C.Orders);
dlo.LoadWith <Order>(o => o.Customer);
Example 3: Longer cycles
Although this should not occur in a well-normalized model, it is possible.
dlo.LoadWith <A>(a => a.Bs);
dlo.LoadWith <B>(b => b.Cs);
dlo.LoadWith <C>(c => c.As);
Example 4: Self recursive subQueries
Example 5: Longer recursive subqueries
The following are some general rules that help you understand what occurs in these scenarios.
LoadWith Each call to LoadWith checks whether cycles have been introduced into the graph. If there are, as in Examples 1, 2, and 3, an exception is thrown.
AssociateWith The engine at run time does not apply the existing SubQuery clauses to the relationship inside the expression.
In Example 4, the Where clause is executed against all A, not just the ones sub-filtered by the SubQuery expression itself (because that would be recursive)
In Example 5, the first Where clause is applied to all the Bs, even though there are subqueries on B. The second Where clause is applied to all the As even though there are subqueries on A.
When you retrieve Customers from the Northwind sample database, you can use to specify that Orders is also to be retrieved. You can even specify which subset of Orders to retrieve.
Available since 3.5
Windows Phone Silverlight
Available since 7.1
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.