Building Linq queries from string in C#4.0 - best practice

倖福魔咒の 提交于 2019-12-21 12:36:28

问题


Currently I am using LinqKit / Ms dynamic query example to dynamically build Linq Expressions from strings. This works fine.

  1. LinqKit: http://www.albahari.com/nutshell/linqkit.aspx
  2. Microsoft dynamic Linq queries: http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

Right now, I am migrating my application from C#3.5 to C#4.0. I am wondering if there is another way (standard way of the framework) to build queries from strings.

I have checked the documentation, but did not find anything yet. Also this is not an issue, since I have the above solution.

Only I'd prefer to use the "standard" features if there some. What's the best practice?


回答1:


I'm currently doing something like this and I'm very happy with the result. The way I did it was with Entity Framework and the ObjectQuery.Select(string query, ObjectParameters[] params) method. More info here: http://msdn.microsoft.com/en-us/library/bb298787.aspx#Y586.

You won't be making expression from string but using SQL to Entities which does the work very well and was made exactly for that purpose as dynamically making Expression isn't trivial and is actually slower.

Cheers



来源:https://stackoverflow.com/questions/4634971/building-linq-queries-from-string-in-c4-0-best-practice

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