c# - OrderBy selector fails while projecting anonymous type -
when using entity framework 5, why work?
var query = categories.select(c => new { products = c.products.orderby(p => p.name) });
while won't?
func<product, string> selector = p => p.name; var query = categories.select(c => new { products = c.products.orderby(selector) });
the thrown exception is: unsupported overload used query operator 'orderby'.
making selector
expression<func<product, string>>
won't work directly , not compile because c.products
not iqueryable<t>
. collection type implementing ienumerable<t>
. enumerable.orderby
not accept expression parameter, delegate.
but ef still needs expression, not delegate. trick use asqueryable()
on navigation collection:
expression<func<product, string>> selector = p => p.name; var query = categories.select(c => new { products = c.products.asqueryable().orderby(selector) });
Comments
Post a Comment