Pass Column Names
MarkBQE opened this issue · 3 comments
MarkBQE commented
How do we pass the column names dynamically to the Where method. Filters is a dictionary with key being the name of the column and Value is the value of the filter, it can be a list of strings, single string. I would like to do something like this, of-course this is pseudo code, in production I will check if the column exists in the database
foreach (var filter in filters)
{
q.Where($"{filter.Key}= @{filter.Value}");
}
Thanks in Advance
Drizin commented
Check the raw modifier in the documentation.
Example here: https://stackoverflow.com/a/63650815/3606250
So you can use like:
q.Where($"{filter.Key:raw} = {filter.Value}");
MarkBQE commented
I was looking into, thanks for the response.
MarkBQE commented
Thanks for all your help. Awesome library, I am able to pass filters dynamically at runtime and everything is working as expected. Cheers :)
foreach (var filter in filters)
{
q.AppendLine($"AND {filter.Key:raw} = {filter.Value.ToString()}");
}