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

Entity Framework IQueryable - specific date

I am trying to filter rows of data on a specific date: The current code takes a dictionary of , and applies the filter to queryable like so: queryable = pageSettings.FiltersDictionary.Aggregate(queryable, (current, keyValuePair) =>…
Matt
  • 619
  • 3
  • 8
  • 23
0
votes
1 answer

Cast BindingList of interface to filter by dynamic linq query knowing the type

I have a bindinglist of type ISomething. That I need to filter with a dynamic linq query. BindingList myList; var myType = typeof(MyClass); (MyClass a class that implements ISomething) I need to be able to cast to a bindinglist of…
David Andrews
  • 71
  • 2
  • 8
0
votes
0 answers

Linq query from a string

I'm trying to build a web application that allows to make any basic linq query (any query that shown here: https://msdn.microsoft.com/en-us/library/bb397927.aspx) on a list with data- iam getting a linq query as a string from the client and want to…
user6003543
  • 13
  • 1
  • 4
0
votes
1 answer

Converting LINQ query to Dynamic Linq

I have a function that looks like this: public void GetAvailableResourcesByLocationChart(List dates, List data) { var totals = (from r in data group new { Dates = r.Dates } by r.Location into g …
arazzy
  • 495
  • 1
  • 8
  • 23
0
votes
2 answers

EF6 IQueryable dynamic linq Where(predicate, values) with DbFunctions.TruncateTime

In my simplified example i have an object with following properties: Name (string) BirthDateTimeStamp (datetime) I need to ba able to build dynamic queries in the following way var predicate = "Name = @0"; var values = new…
JMan
  • 2,611
  • 3
  • 30
  • 51
0
votes
2 answers

How to refer to a field in a dynamic linq query?

I have a query that needs to be dynamic, I think most of my syntax is right but I do not know how to give it the name of the column I want to group by. I have tried a few different approaches and I always get an error - "No property or field 'name'…
Ronan
  • 41
  • 1
  • 4
0
votes
1 answer

Does dynamic GroupBy work together with dynamic Where in dynamic LINQ?

I use this dynamic LINQ library together with Linq-to-Entities. I build query and after that iterate it with foreach(object e in query){} query=db.Table1.Where("it.FieldA>10").Select("it.FieldB");…
alpav
  • 2,972
  • 3
  • 37
  • 47
0
votes
0 answers

Dynamic LINQ: GroupBy for MongoDB queryable collection

I am trying to do a MongoDB aggregate using LINQ, with the MongoDB .NET Driver version 2.1 and .NET 4.5, using ScottGu's Dynamic LINQ library. This is a simplified schema for the data stored in MongoDB: { "_id" : "151207.01.02", …
The Don
  • 343
  • 2
  • 13
0
votes
0 answers

No applicable aggregate method 'FirstOrDefault' exists

We are building search query using dynamic link . There one property has one to many relationship. There for we use FirstOrDefaylt. But when it going to execute it gives message of "No applicable aggregate method 'FirstOrDefault' exists". This is…
0
votes
3 answers

How to convert an anonymous type in Dynamic LINQ to a strong type

This is a bit of a multi-faceted question, so let me just dive into the code with some explanation at the bottom. Example Sample Data: List input Id, Facility, HospitalService, Field3, Field4, Field5, ... 1, 1, A, …
Raymond
  • 3,382
  • 5
  • 43
  • 67
0
votes
0 answers

Unable to cast object of type 'System.Reflection.RuntimeConstructorInfo' to type 'System.Reflection.MethodInfo'

I am using Dynamic LINQ in an ASP.NET MVC project to create queries at runtime. First I create a string from client's request like this: string predicate = GetPredicateString(request); The predicate would have a value like "AvailableFrom =…
Kamran
  • 782
  • 10
  • 35
0
votes
1 answer

How to do a All() using Dynamic LINQ

as the same as here: How to do a Sum using Dynamic LINQ I want to do a All() with a dynamic string... My code: allDataValid = consumptionModelListOld.All(x => x.F11ValueValid); I want to write: allDataValid =…
Rene Koch
  • 317
  • 3
  • 13
0
votes
1 answer

How to GroupBy a part of DateTime using System.Dynamic.LINQ library

I have tables that contain a lot of rows, each record is excellent by whom and on what date was added. I want to group all records, based on AddedBy and AddedOn fields. The problem is that the dates are in full including the miliseconds and I only…
Haim Tabak
  • 185
  • 1
  • 11
0
votes
0 answers

Dynamically creating LINQ query with dynamic connection string

I am trying to page a large set of data using IQueryable. Take method for a query that I am building dynamically. I was going to use the take method so I can keep taking until I have read the entire large dataset. Basically, I am reading the data in…
Paul
  • 53
  • 1
  • 7
0
votes
1 answer

How to parse xml data with dynamic linq

i am reading a xml file and querying by LINQ this below way XDocument document = XDocument.Load(xmlFilePath); var query = document.Descendants("orders").Select(c => c); query = query.OrderBy(sortColumn + " " + OrderDirection); query =…
Thomas
  • 33,544
  • 126
  • 357
  • 626