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
0
votes
1 answer

Cast ITable to IEnuerable - Dynamic LINQ to SQL Query with no DataTable information
I need to write dynamic LINQ where I know nothing about the input table - data provider (which is why I'm using LINQ to SQL), no table name, nothing. I want to be able to query the data given user-selected fields and given values, something like…
dashnick
  • 2,020
  • 19
  • 34
0
votes
0 answers

Dynamic Linq does not remember properties of a property

I am using Dynamic Linq to sort my database based on a string. However it throws an error saying: The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are…
user2657943
  • 2,598
  • 5
  • 27
  • 49
0
votes
3 answers

Dynamic lambda expression for where clause

I have a dynamic list of objects on which I am using lambda expression where clause to filter items. For example, just consider that it have 3 properties, foo, bar and baz class item // let this be current class in dynamic item list { bool…
Chaitanya Gadkari
  • 2,669
  • 4
  • 30
  • 54
0
votes
1 answer

Dynamic Linq Querystring not working with mixed operators along with contains

I have used Dynamic Linq in my application and unfortunately it's not working. Here is my sample code. List contains = new List() { "Poland", "Ecuador" }; List array = new…
KNIGHT
  • 11
  • 3
0
votes
1 answer

Disitinct Dynamic Linq

To get Distinct values, I need an IEnumerable. var results = gridData.Select(r => r.ExplicitColumnName).Distinct(); To decide the column name at run time, I need to use an IQueryable as required by System.Linq.Dynamic. var results =…
stardotstar
  • 318
  • 2
  • 18
0
votes
2 answers

Dynamic LINQ - Entity Framework 6 - Update Records for Dynamic Select

C# rookie. Below is my code, been trying for hours now to get this to update some fields in my DB and tried many different implementations without luck. // Select all fields to update using (var db = new Entities()) { …
user3333134
  • 389
  • 1
  • 6
  • 17
0
votes
1 answer

Using Linq.Dynamic where method with a dynamic list gives error

I am reading some JSON and converting it to a dynamic list. Below is My Code: dynamic data = JObject.Parse(response); var result = data.result; var result = ((IEnumerable)arr).Cast().ToList(); var id = result[0].id; var filtereddata =…
Anshuman Jasrotia
  • 3,135
  • 8
  • 48
  • 81
0
votes
1 answer

Can SqlFunctions work with Dynamic Linq?

Is it possible to get SqlFunctions to work with Dynamic Linq? I noticed this post from the SO site which seems to suggest that it is possible, however, every time I run this query below in a .NET project (not .NET…
methon.dagger
  • 505
  • 9
  • 28
0
votes
0 answers

How to filter date in server side using dynamic linq?

I want to filter dates range. I'm using the dynamic LINQ library. I have to build my where string into a variable based on several factors and then pass the string variable to the where clause. In my ASP.NET MVC project I wrote a helper. private…
0
votes
0 answers

How to write two-step first-l2e-then-l2o IQueryable?

Let's say I have an Entity Framwork query var query = db.Entities .FancyQueryStuff() .Where(GetFilter()) // * .OrderBy(GetSort()) // * .Take(GetNumberOfRows()) // * ; and figure that this query is very slow. Testing reveals that the…
John
  • 6,693
  • 3
  • 51
  • 90
0
votes
2 answers

Follow navigation property in dynamic linq

I'm trying to use dynamic linq to query data. Now I have a (normal) linq query like: from u in c.Users from d in u.Documents select d.DocumentID I'm looking for the equivalent of this in dynamic linq. The emphasis is on how to navigate from the…
PaulVrugt
  • 1,682
  • 2
  • 17
  • 40
0
votes
2 answers

LOWER and REPLACE doesn't work on dynamic linq where statement

Here is my code , db.myDBContext.my_tables.Where("REPLACE(LOWER(name),\" \",\"\") == \"{0}\"", value); it show the error No applicable method 'LOWER' exists in type 'my_table' can't I use REPLACE and LOWER in dynamic linq clause ?
zey
  • 5,939
  • 14
  • 56
  • 110
0
votes
1 answer

Entity Data Model, Dynamic Linq, multiple table dynamic Where clause, strongly typed return types

When writing a method for an oData service I have the below linq, for which I need to have a dynamic "where" clause to filter the results (the "new"s in the joins are for composite PKs in the Entity Data Model): var query = from pl in…
rposbo
  • 327
  • 1
  • 10
0
votes
1 answer

How to construct dynamic LINQ query string be for a query that looks like *abc*def*

I am using Dynamic LINQ for one of my projects to filter arrays. Library can be downloaded from NuGet Gallery link or Codeplex link. I am using version 1.0.6 from NuGet link. It is the same as LINQ but the condition can be specified using…
mrbubz
  • 427
  • 2
  • 6
  • 20
0
votes
2 answers

Dynamic Linq creates multiple queries

The following linq call in plain linq to sql results in 1 SQL query to the database Table1.Select(t => new {Table2.First().Property1}) But I can't seem to get Dynamic Linq to to the same, the below produces 2 separate…
OrdinaryOrange
  • 2,420
  • 1
  • 16
  • 25