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

How to use Dynamic LINQ in MVC4?

This is the default action from the "View" of my MVC4 application. public ActionResult Index(string sort = "R_ResDate", string sortdir = "DESC", int page = 1) { List results =…
user2557841
0
votes
1 answer

Dynamic linQ on string array

I have a string array like this. string[] ColumnArray = new string[] { First story, second data , third way }; Following is the linQ query on this array. string query = (from x in ColumnArray where x.Contains("Story") …
Dev
  • 309
  • 1
  • 8
  • 24
0
votes
1 answer

IQueryable type to an Array

I have a dynamic Linq query like this. I need to convert the result set into an array. But I am not able to convert the IQueryable type to an Array. Any suggestion? my code:- var query = Data.AsEnumerable() .AsQueryable() …
Dev
  • 309
  • 1
  • 8
  • 24
0
votes
1 answer

Dynamic Linq Any syntax

I am trying to figure out how to use Any operator in Linq.Dynamic, here is my test code: var bar = new[] { new {Bar = "A", Id = 1}, new {Bar = "B", Id = 1}, new {Bar = "C", Id = 2}, new {Bar = "A", Id = 2}, new {Bar = "B", Id =…
Tom
  • 15,781
  • 14
  • 69
  • 111
0
votes
2 answers

Using special property names in Dynamic LINQ

I'm constructing a Dynamic LINQ query like this: "Guid=Guid(\"" + entityId + "\")" This is eventually passed into a .Where() query, somewhere in the code that I call. I'm getting this error: ParseException: '.' or '(' expected This seems to be…
Kendall Frey
  • 43,130
  • 20
  • 110
  • 148
0
votes
3 answers

Dynamic where clause in LINQ to Objects

I know there are a lot of examples of this on the web, but I can't seem to get this to work. Let me try to set this up, I have a list of custom objects that I need to have limited on a range of values. I have a sort variable that changes based on…
Clarence Klopfstein
  • 4,682
  • 10
  • 33
  • 47
0
votes
1 answer

How can I access the result of dynamic linq with dynamic key/value pairs of IEnumerable?

I have a Dynamic Linq query, through which am trying to access grouped data, grouped on two columns, and 1 columns on which aggregation function is used. var gFieldList = new List() { "Supplier", "Country" }; var sFieldList = new…
0
votes
1 answer

How to build Dynamic Linq from Request.QueryString?

I'm currently working on feature to implement/build a filter through Request.QueryString. The idea here is the filter can be on any property with in the Model For ex., public class Alert{ public string Name; public string Status; public…
Ram
  • 43
  • 4
0
votes
3 answers

How to get value from string expression

I have a string stored in my db: "Users.ElementAt(1).LastName" I then have an object like so: MyClass myclass = new MyClass () { Users = new List() { new User() { …
Steve Stokes
  • 1,200
  • 18
  • 36
0
votes
1 answer

Building a dynamic anonymous type Select statement using Linq

//list is IEnumeable NOT IEnumerable var IEnumerable = list.AsQueryable().Cast().Select(x=> .........); object actually has a POCO underlying Anonymous class e.g AccountId,Name,SecretInfo What I want in the select statement is…
chugh97
  • 9,602
  • 25
  • 89
  • 136
0
votes
0 answers

how can I extend dlinq class to have empty strings last in a sort

How can extend the dynamic linq class to sort empty strings last in the sort order using a sort string expressing? query.OrderNullsLast("Col1 ASC, Col2 DESC, Col3 ASC") So the result is 'A', 'B', 'C', '' Something like this, but accepting a string…
Jon.ee
  • 95
  • 2
  • 8
0
votes
2 answers

Dynamic Linq Query not working with DateTime field

I am using Dynamic linq to provide my MVC app with data and I have trouble with DateTime fields. The objects I'm parsing through has a System.Datetime field and I want to check if the dates correspond. So I try to build the string like this (I'm…
hsim
  • 2,000
  • 6
  • 33
  • 69
0
votes
2 answers

DynamicLinq C# not working in join

I am using in my C # projects DynamicLinq. When I do a simple select using "order by", "skip", etc. works perfectly. But if you do join restona simple error: Error 3 Instance argument: cannot convert from 'int?' to 'System.Linq.IQueryable' …
Tiedt Tech
  • 719
  • 15
  • 46
0
votes
1 answer

Dynamic linq unable to parse ordering

Say I have a query that selects into a defined type like so: public class SomeObject { public DateTime CreatedDate { get; set; } } private class MyType { internal SomeObject Object1 { get; set; } internal SomeThing Object2 { get; set;…
Oxymoron
  • 1,382
  • 4
  • 20
  • 40
0
votes
1 answer

Dynamic LINQ API - SQL Convert Function

I'm trying to use a Dynamic LINQ Query to query a SQL database, and in the Where clause I need to evaluate an '=' condition with a field that is of type TEXT. Right now, I've got this: var result = DBCon.PcInValue .Where(String.Format("InputName…
Overhed
  • 1,289
  • 1
  • 13
  • 41