ObjectTransactionFindFirstOrDefaultTObject Method (Repository, ExpressionFuncTObject, Boolean, FuncTObject, Boolean) |
Searches through both committed and uncommitted objects for a single object, matching the predicate.
Returns null if not found.
This overload could be used if the search requires type casting to intermediate object type.
Namespace:
Aloe.SystemFrameworks.Domain
Assembly:
Aloe.SystemFrameworks.Domain (in Aloe.SystemFrameworks.Domain.dll) Version: 20.1.3.5
Syntaxpublic TObject FindFirstOrDefault<TObject>(
Repository repository,
Expression<Func<TObject, bool>> predicate,
Func<TObject, bool> compiledPredicate = null
)
where TObject : DomainObject
Public Function FindFirstOrDefault(Of TObject As DomainObject) (
repository As Repository,
predicate As Expression(Of Func(Of TObject, Boolean)),
Optional compiledPredicate As Func(Of TObject, Boolean) = Nothing
) As TObject
public:
generic<typename TObject>
where TObject : DomainObject
TObject FindFirstOrDefault(
Repository^ repository,
Expression<Func<TObject, bool>^>^ predicate,
Func<TObject, bool>^ compiledPredicate = nullptr
)
member FindFirstOrDefault :
repository : Repository *
predicate : Expression<Func<'TObject, bool>> *
?compiledPredicate : Func<'TObject, bool>
(* Defaults:
let _compiledPredicate = defaultArg compiledPredicate null
*)
-> 'TObject when 'TObject : DomainObject
Parameters
- repository
- Type: Aloe.SystemFrameworks.DomainRepository
The repository to search. - predicate
- Type: System.Linq.ExpressionsExpressionFuncTObject, Boolean
The predicate to match. - compiledPredicate (Optional)
- Type: SystemFuncTObject, Boolean
The compiled predicate.
Should be the same predicate, but in compiled form.
If not specified, the compilation occurs in runtime.
Type Parameters
- TObject
- The type of the object. If it is unknown, use DomainObject.
Return Value
Type:
TObject
The found object or null.
Remarks
Because it knows, that it has to find only a single object, the method
searches first locally and queries the data source only if no object is found locally.
This method overload could be used, when the search requires the lambda predicate to use the properties
of an intermediate object type, while the final object type is unknown at compile time.
Still, this overload should be used only when the final object type is known at runtime and represented
by the final object repository. For example, this searches through all objects, represented by
the specified repository while using only the Document properties for the lambda:
Examples
var doc = transaction.FindFirstOrDefault<Document>(specificDocumentTypeRepository, d => d.DocumentDate > someDate);
This overload is required, since type casting is not supported for data source queries.
See Also