Click or drag to resize

LinqExtensionsPreloadTSource, TResult Method (IEnumerableTSource, ExpressionFuncTSource, TResult)

Preloads the full object state for all objects returned by applying the expression to each element in source. This is still a research method, which will be renamed later to .Preload().

Namespace:  Aloe.SystemFrameworks.Domain.LINQ
Assembly:  Aloe.SystemFrameworks.Domain (in Aloe.SystemFrameworks.Domain.dll) Version: 20.1.3.5
Syntax
public static IEnumerable<TSource> Preload<TSource, TResult>(
	this IEnumerable<TSource> source,
	Expression<Func<TSource, TResult>> expression
)
where TSource : DomainObject
where TResult : ILazyObject

Parameters

source
Type: System.Collections.GenericIEnumerableTSource
The source.
expression
Type: System.Linq.ExpressionsExpressionFuncTSource, TResult
The selector.

Type Parameters

TSource
The type of the source domain objects.
TResult
The type of the result domain objects.

Return Value

Type: IEnumerableTSource
The same source objects enumeration.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableTSource. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Remarks

Expression is usually a foreign key expression, similar to:

invoices.Preload(inv => inv.Customer);

The above code will preload with a single command all customers, referenced by the invoices.

You can also use Preload in a chain of commands like in the following example:

var so = Transaction.Query<SalesOrder>().ToList()
  .Preload(so => so.Customer)
  .Preload(so => so.Store)
  .Select(so => so.DocumentCurrency == c);

Preload can only be used on IEnumerable, e.g. over the results of a query.

It is not suggested to use expressions chaining many objects, as this might trigger many single object loads. For example this, although legal and working is not suggested:

//not suggested as this might trigger many single customer loads
invoices.Preload(inv => inv.Customer.EnterpriseCompany);

//This is ok. First ensure that intermediate objects are loaded:
invoices.Preload(inv=>inv.Customer).Preload(inv=>inv.Customer.EnterpriseCompany);
See Also