Hello,
what is the best way to build the Filter string dynamically because we have a lot of parameters?
(only to concatenate the strings?)
here is only a query with one parameter "search":
pfuschertyps = await PDBService.GetPfuschertyps(new Query { Filter = $@"i => i.Pfuschertyp1.Contains(@0)", FilterParameters = new object[] { search } });
robert
enchev
January 27, 2023, 10:11am
2
You can append to this expression. For example:
$@"i => i.Pfuschertyp1.Contains(@0) || i.SomeOtherProp.Contains(@0)"
If you pass additional parameter you can use the parameter index:
pfuschertyps = await PDBService.GetPfuschertyps(new Query { Filter = $@"i => i.Pfuschertyp1.Contains(@0) || i.SomeOtherProp.Contains(@1)", FilterParameters = new object[] { search, someOtherParameter } });
I know that but I want to buld the expression dynamically because some parameters sould only added if they are not null...
enchev
January 27, 2023, 10:26am
4
Since you already know how the Query is constructed you can do it programmatically as well.
OK that means there is no better way to buld the Query.Filter string as concatenate the strings- right?
((I'm not so familiar with Entity Framework)
robert
enchev
January 27, 2023, 11:11am
6
This API is related to Radzen.Blazor only built on the top of Dynamic LINQ expressions. There is no default high level EF API that allows building dynamically Where().