Problem with dynamic LINQ brackets

I am using the Dynamic Linq Library ( this ) in my .NET MVC application to query a SQL Server database. So far, everything is working fine.

However, the Linq dynamic library gives the "Expression expected" error when I use square brackets to indicate problematic column names containing spaces or hyphens. Here are some examples:

var query = context.FetchIceCream().AsQueryable().Where("Chocolate = 1"); // This is fine var query = context.FetchIceCream().AsQueryable().Where("[Rum and Raisin] = 1"); // This results in an "Expression expected" error 

I cannot rename column names, so this is not an option - I need to be able to sort this in code. I searched high and low to solve this, but to no avail ... please help keep my sanity!

+6
source share
2 answers

So, I think this is the answer:
The name you use in the Where clause must be a property of the object that you have in the Queryable collection.

+2
source

I would advise against using Dynamic LINQ at all. Queries can be built step by step simply by adding things to the IQueryable<T> .

0
source

Source: https://habr.com/ru/post/922374/


All Articles