Basically I would like to use predicate builder to construct a FieldCompareRangePredicate.
Is this supported?
This is the code that I would like to write...
System.Linq.Expressions.Expression<Func<WorkOrderEntity, bool>> predicate = PredicateBuilder.Null<WorkOrderEntity>();
predicate = predicate.And(wo => wo.Project.ClientId == searchVo.OrganizationIds);
Where searchVo.OrganizationIds is of type long[].
This code does not compile saying that "Operator '==' cannot be applied to operands of type 'long' and 'long[]'"
I can replace the code above with the next snippet, but this only handles 1 item in the array, not all of them.
System.Linq.Expressions.Expression<Func<WorkOrderEntity, bool>> predicate = PredicateBuilder.Null<WorkOrderEntity>();
predicate = predicate.And(wo => wo.Project.ClientId == searchVo.OrganizationIds[0]);
I suppose I could iterate through the array using following code (which ends in the same result)...
System.Linq.Expressions.Expression<Func<WorkOrderEntity, bool>> predicate = PredicateBuilder.Null<WorkOrderEntity>();
foreach (var clientId in searchVo.OrganizationIds)
{
predicate = predicate.Or(wo => wo.Project.ClientId == clientId);
}
However isnt it preferred to have TSQL That uses predicates that say "where clientId IN (1,2,3)" vs "where clientId = 1 or clientId =2 or clientId = 3" ? Or does SQL Server convert the IN clause into multiple OR statements?