How do I build up LINQ dynamically

前端 未结 3 822
青春惊慌失措
青春惊慌失措 2020-12-10 06:50

I have a scenario where I have custom configured column names, associated operators like < > = between etc. and then a value associated.

I\'m trying to determine

相关标签:
3条回答
  • 2020-12-10 07:18

    Actually, there is a specific library from Microsoft (System.Linq.Dynamic) that comes with the C# VS2008 samples that supports this. Get it from here (Microsoft Download)

    The library is included in the \LinqSamples\DynamicQuery directory of the samples of above download.

    For extensive usage examples check this page: http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

    0 讨论(0)
  • 2020-12-10 07:21

    If you are talking about a string Where clause (rather than building the expression etc yourself) - then the Dynamic LINQ Library (in the 3.5 samples, IIRC) should suffice.

    Note that the example below is for database usage; but you can use it with LINQ-to-Objects by calling .AsQueryable() on your in-memory data.

    0 讨论(0)
  • 2020-12-10 07:21

    Also you can use expression trees to created dynamic queries. See:

    http://msdn.microsoft.com/en-us/library/bb397951.aspx

    http://www.interact-sw.co.uk/iangblog/2005/09/30/expressiontrees

    http://blogs.msdn.com/charlie/archive/2008/01/31/expression-tree-basics.aspx

    0 讨论(0)
提交回复
热议问题