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
Syntaxpublic static IEnumerable<TSource> Preload<TSource, TResult>(
this IEnumerable<TSource> source,
Expression<Func<TSource, TResult>> expression
)
where TSource : DomainObject
where TResult : ILazyObject
<ExtensionAttribute>
Public Shared Function Preload(Of TSource As DomainObject, TResult As ILazyObject) (
source As IEnumerable(Of TSource),
expression As Expression(Of Func(Of TSource, TResult))
) As IEnumerable(Of TSource)
public:
[ExtensionAttribute]
generic<typename TSource, typename TResult>
where TSource : DomainObject
where TResult : ILazyObject
static IEnumerable<TSource>^ Preload(
IEnumerable<TSource>^ source,
Expression<Func<TSource, TResult>^>^ expression
)
[<ExtensionAttribute>]
static member Preload :
source : IEnumerable<'TSource> *
expression : Expression<Func<'TSource, 'TResult>> -> IEnumerable<'TSource> when 'TSource : DomainObject when '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:
IEnumerableTSourceThe 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).
RemarksExpression 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:
invoices.Preload(inv => inv.Customer.EnterpriseCompany);
invoices.Preload(inv=>inv.Customer).Preload(inv=>inv.Customer.EnterpriseCompany);
See Also