Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with dynamic LINQ queries containing brackets

I'm using the Dynamic Linq Library (this one) in my .NET MVC application to query a SQL Server database. It's all working fine so far.

However, the Dynamic Linq Library gives an "Expression expected" error whenever I use square brackets to designate troublesome 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'm not able to rename any column names, so that's not an option - I need to be able to sort this out in code. I've searched high and low for a solution to this but to no avail... please help to save my sanity!

like image 361
Chris Avatar asked Aug 08 '12 15:08

Chris


1 Answers

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

like image 78
Patrick Koorevaar Avatar answered Nov 12 '22 11:11

Patrick Koorevaar