Pass string of "." as a Where() condition generates error: "No property or field '' exists in type ''"

c# dynamic-linq entity-framework linq sql-server


Currently, I build query statement by using dynamic-linq library.

And I have an issue when I execute this query:

query = query.Where("Table1.Column2.Contains(@0)", new string[] { "test" });


  • Table1: a table name in my database
  • Column2: a column name inside Table1

As a result, it throws an error:

No property or field 'Table1' exists in type 'Table1'

I have made sure, the naming are correct. A friend of mine, he also uses exactly the same library and he can execute it successfully in different database, MSSQL 2014. I am using MSSQL 2008.

When I try to do it in different way like:

query = query.Where("Column2.Contains(@0)", new string[] { "test" });

It works fine..

I am wondering, in my case, I have to use the first approach instead. That's why, what am I doing wrong with it?

11/8/2017 4:44:14 PM

Popular Answer

My understanding is that Dynamic Linq is still operating on objects, not passing what you write directly through to SQL? So you can only add conditions on things that are properties of the underlying object. Now these may be defined as being populated from various columns in a database, but they don't have to be...

I think you're basically trying to do this sort of thing:

class x
    int SomeProperty{get;set;}
var instance = new x();
instance.SomeProperty = 1;

//compile Error: x is not a property of an instance of x
if (instance.x.SomeProperty==1)  
   // ..Do things
11/8/2017 4:58:16 PM

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