mrJack
mrJack

Reputation: 1011

Dynamic linqToEntity in c#

my code :

public List<Book> GetBook()
{
    var q = this.Entities.Book.Where("IdBook>1").ToList();
    return (q);
}

error :

'IdBook' could not be resolved in the current scope or context. Make sure that all referenced variables are in scope, that required schemas are loaded, and that namespaces are referenced correctly. Near simple identifier, line 6, column 1.

What is the correct code?

Upvotes: 1

Views: 280

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364259

Linq doesn't allow using strings as expression unless you are using Dynamic Linq library (in such case the error says that IdBook doesn't exists). If you are not using Dynamic Linq library and you still have Where extension method accepting string it is a method expecting valid Entity SQL expression so try:

var q = this.Entities.Book.Where("it.IdBook > 1").ToList();

Upvotes: 2

Related Questions