Questions tagged [dynamic-linq]

Dynamic LINQ is a small library on top of the .NET framework 3.5 or later which allows to build string based query expressions. A common use case is to create LINQ queries at runtime in contrast to constructing queries at compile time.

Dynamic LINQ is a small library on top of the .NET framework 3.5 or later which allows to build string based query expressions.

Dynamic LINQ is not part of the .NET framework but is provided as a sample to Visual Studio 2008. The single C# file consists of the namespace System.Linq.Dynamic which includes a set of extension methods for IQueryable<T> - for instance overloads of Where, Select, OrderBy, GroupBy which expect a string as parameter instead of a lambda expression to define a query.

The query string is parsed and transformed into an expression tree by using Reflection. The Dynamic LINQ extension methods throw a ParseException if the syntax of the query string is invalid or the string contains unknown operators or properties.

Dynamic LINQ can be used with any LINQ data provider like LINQ to Objects, LINQ to Entities, LINQ to SQL or LINQ to XML.

Example in C#

The strongly-typed LINQ query ...

var query = Northwind.Products
                     .Where(p => p.CategoryID == 2 && p.UnitPrice > 3)
                     .OrderBy(p => p.SupplierID);

... can be expressed in Dynamic LINQ in the following way:

var query = Northwind.Products
                     .Where("CategoryID = 2 And UnitPrice > 3")
                     .OrderBy("SupplierID");

Links

Dynamic LINQ (Part 1: Using the LINQ Dynamic Query Library)

573 questions
-3
votes
2 answers

How to create linq WHERE IN statement without using Contains()

I have a situation where I am using a linq provider that does not support the .Contains method to generate a WHERE IN clause in the query. I am looking for a way to generate the (Value = X OR Value = Y OR Value = Z) statement dynamically from the…
Jason Rodman
  • 71
  • 1
  • 5
-3
votes
1 answer

How can I convert the following linq queries to a (Having) like in SQL

My intentions are to aggregate the results instead of narrow them down. if (Request.QueryString["VenueType"] == null) Renders = _renderContext.Renders; else { List venueTypeIds = Request.QueryString["VenueType"].Split(',') …
Eric Bishard
  • 5,201
  • 7
  • 51
  • 75
-3
votes
1 answer

Return a collection of an anonymous type with dynamic linq

Apparently, the Dynamic LINQ Library has the ability to return a collection of an anonymous type. However, I am not exactly sure how to do this. I basically just need to build the following using Dynamic LINQ var result = from s in…
jjc99
  • 3,559
  • 4
  • 22
  • 21
1 2 3
38
39