Filtering over Sql.ExpressionMethod alike property having aggregate complex expression
See original GitHub issueHi,
Similar to Sql.ExpressionMethod we have construct to create expressions assigned to scalar property. Grids are normally shown with this expression and it works fine, problem is when we want to filter this subquery linq Expression, e.g. . …where ChecklistTriggers like ‘%Hired%’ (ChecklistTrigger defined below)
We are having hundreds of Expressions for properties and we have issues with few of them using Association.Any + StringAggregate. If we remove checklist.ChecklistTriggers.Any call, it is working fine, but that is not correct for our business logic.
public <Func<Checklist, string>> ChecklistTriggers
{
return checklist => checklist.ChecklistTriggers.Any()
? checklist.ChecklistTriggers.AsQueryable()
.Select(x => x.TriggerType == TriggerType.Hired ? "Hired" :
x.TriggerType == TriggerType.PreHired ? "PreHired" :
x.TriggerType == TriggerType.Terminated ? "Terminated" : ""
)
.StringAggregate(",").ToValue()
: "None";
}
For version 3.2.3. we get “The method or operation is not implemented.” and for 3.4.5. we get “Cannot perform an aggregate function on an expression containing an aggregate or a subquery.”. Query for 3.4.5. version seems complicated, instead of using subquery, it is duplicated for filter and for normal grid column, strange.
Using Coalesce did not help, the same error.
public <Func<Checklist, string>> ChecklistTriggers
{
return checklist => checklist.ChecklistTriggers.AsQueryable()
.Select(x => x.TriggerType == TriggerType.Hired ? "Hired" :
x.TriggerType == TriggerType.PreHired ? "PreHired" :
x.TriggerType == TriggerType.Terminated ? "Terminated" : ""
)
.StringAggregate(",").ToValue() ?? "None";
}
Environment details
linq2db version: 3.2.3. and 3.4.5. Database Server: Sql Server 2019 Database Provider: SQL Operating system: W10 .NET Framework: 4.8.2
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (6 by maintainers)
Hi, here is an example:
Probably next thursday