Issue with dynamic LINQ queries containing brackets

.net dynamic-linq linq sql sql-server

Question

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!

1
6
8/27/2012 10:44:35 AM

Popular Answer

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.

2
8/27/2012 8:27:53 AM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow