CriteriaOperator.FromLambda<TModel>(Expression<Func<TModel, Boolean>>) Method
Converts the specified LINQ-like expression to its CriteriaOperator equivalent.
Namespace: DevExpress.Data.Filtering
Assembly: DevExpress.Data.v26.1.dll
NuGet Package: DevExpress.Data
Declaration
public static CriteriaOperator FromLambda<TModel>(
Expression<Func<TModel, bool>> lambda
)
Parameters
| Name | Type | Description |
|---|---|---|
| lambda | Expression<Func<TModel, Boolean>> | A LINQ expression to convert. |
Type Parameters
| Name | Description |
|---|---|
| TModel | A type of object to which the expression is applied. |
Returns
| Type | Description |
|---|---|
| CriteriaOperator | A criteria operator created from the specified expression. |
Remarks
Use the FromLambda method to create a criteria operator from a LINQ-like predicate expression:
// Returns "[Company] = 'DevExpress'"
CriteriaOperator simpleCriteria = CriteriaOperator.FromLambda<User>(u => u.Company == "DevExpress");
// Returns "[Products][].Avg([Price]) > 100.0"
CriteriaOperator complexCriteria = CriteriaOperator.FromLambda<Supplier>(supplier => supplier.Products.Average(product = > product.Price) > 100 );
// Returns "[Angle] < Acos(10)"
CriteriaOperator mathCriteria = CriteriaOperator.FromLambda<Shape>(shape => shape.Angle < Math.Acos(10));
Tip
For information on how to build LINQ-like expressions, refer to the following topic: LINQ-Like Criteria Syntax
Important
The FromLambda method creates a CriteriaOperator instance from a compiled LINQ expression. The resulting criteria expression may be affected by C# compiler behavior. For example, enum values used in lambda expressions may be compiled as integer constants, causing the resulting criteria expression to contain an integer value instead of the corresponding enum value.
If preserving the enum value in the criteria expression is important, use the Parse method instead. Unlike FromLambda, Parse does not rely on the compiled representation of the lambda expression and therefore avoids these compiler-specific limitations.