OrderBy(“it.” + sort) — Hard coding in LINQ to Entity framework?

半世苍凉 提交于 2019-12-03 15:28:47

The it.Name syntax is ESQL and is indeed specific to the EF. There are good reasons to use this sometimes (e.g., collation specifiers), but it's not what I normally do.

Usually I use standard LINQ expressions:

var query = context.Customer.OrderBy(p => p.Name);

You can also use System.Linq.Dynamic, if you download it from Code Gallery, and then your original query:

var query = context.Customer.OrderBy("Name");

...will work.

No nice way, so far

My answer to this question was to create a stored procedure which has parameter to control sorting.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!