开发者

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

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 开发者_Python百科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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜