OrderBy("it." + sort) -- Hard coding in LINQ to Entity framework? -
i have been trying use dynamic linq entity in application specifying orderby attribute @ runtime. when using code described in majority of documentation:
var query = context.customer.orderby("name");
i received following exception:
system.data.entitysqlexception: 'name' not resolved in current scope or context. make sure referenced variables in scope, required schemas loaded, , namespaces referenced correctly.
after searching found msdn page:
http://msdn.microsoft.com/en-us/library/bb358828.aspx
which included following code example:
objectquery<product> productquery2 = productquery1.orderby("it.productid");
this prompted me change code following:
var query = context.customer.orderby("it.name");
after code works perfectly. able confirm indeed correct way orderby working linq entity? can’t believe framework have been implemented in way, perhaps have overlooked something?
thanks, matt
the it.name
syntax esql , indeed specific ef. there reasons use (e.g., collation specifiers), it's not do.
usually use standard linq expressions:
var query = context.customer.orderby(p => p.name);
you can use system.linq.dynamic, if download code gallery, , original query:
var query = context.customer.orderby("name");
...will work.
Comments
Post a Comment