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
2 answers

Linq Expression Builder datetime.year compare

Currently I am using expression builder for dynamic query generation. I have created dynamic expressions for int, date time, and string operators. Now I am stuck at one point . I want to compare month part of datetime through expression. We are…
0
votes
1 answer

How to use linq extensions with Func parameters in Dynamic Linq expressions?

While somewhat powerful, the System.Linq.Dynamic library has a surprising lack of documentation, especially in regards to what conventions must be followed for more complex queries. In a query I'm working on, it contains a FirstOrDefault call, but…
Mark Rogers
  • 96,497
  • 18
  • 85
  • 138
0
votes
2 answers

Kendo Grid not calling correct DynamicLINQ method

My grid won't call my parameterized DataSourceResult methods. It just calls the parameterless one. I've studied this article till my eyes are falling out. What am I missing? From my javascript controller: $("#grid").kendoGrid({ dataSource: { …
John Mc
  • 212
  • 2
  • 16
0
votes
1 answer

DataTable - Dynamic Linq OrderBy using Lambda expressions

I'm getting a collection of records in a DataTable and binding it to a grid control. Before binding it I'm sorting the data based on few conditions. For brevity I'm will explain a test scenario. I've two fields Category and Country. I want to first…
NLV
  • 21,141
  • 40
  • 118
  • 183
0
votes
3 answers

Dynamic Linq Library Help

I have the following class: public class Item { public Dictionary Data { get; set; } } and a list of it: List items; I need to filter and order this list dynamically using SQL-Like strings. The…
Alon Gubkin
  • 56,458
  • 54
  • 195
  • 288
0
votes
2 answers

How to create a dynamic where clause?

in this below code string cluase = string.Empty; string whereValue = string.Empty; foreach (var i in whereCluaseItems) { if (cluase != "") { cluase += " and " + i.Name; } else { cluase = i.Name; } if…
0
votes
0 answers

Dynamic linq join extension method usage

I'm trying to test out a dynamic join extension method as defined here to join products with categories in the Northwind SQL database. However I'm not 100% familiar with lambda expressions and fail to understand how to make the following SQL query…
JohanLarsson
  • 475
  • 1
  • 8
  • 23
0
votes
1 answer

Pass in a field name at run time using Dynamic LINQ library?

This is a small application used on a company intranet by 4 people at the most, and I am new to C# and .NET, so the solution does not have to be grandiose. I am trying to create a search field for simple .NET C.R.U.D app where the user can pick a…
jazzcat
  • 3
  • 3
0
votes
1 answer

Dynamic linq syntax for subquery

I want to have the following query in Dynamic LINQ.. I have tried some solutions but have not succeeded yet. select SUM([Value1]) AS [Sum] ,[Dim1] AS [Primary], [Dim2] AS [Secondary] from ( SELECT …
JohanLarsson
  • 475
  • 1
  • 8
  • 23
0
votes
1 answer

How do I fix error "No property or field 'Color' exists in type 'String'"

Using Dynamic Linq and the entity frame work I have the below code: private void ComboBox_DropDown(object sender, EventArgs e) { ComboBox cb1 = (ComboBox)sender; string SelectField = cb1.Name.Substring(2); var query =…
user2125348
  • 430
  • 1
  • 7
  • 21
0
votes
1 answer

Dynamic Linq Query and Expression

I would like to build a dynamic query but failed to get the required result. Please see the below code. I have tried using two different approach. Simple Linq , the result is "resultUsingLing" in the below code. Dynamic Linq the result is…
Binod
  • 313
  • 1
  • 2
  • 12
0
votes
1 answer

Use Dynamic LINQ Library with join

Following is the UI : And this is code snippet i am using to fire dynamic where clause : public void bind() { string filter = ""; if (!string.IsNullOrEmpty(txtPart.Text)) { filter = filter +…
Sunny
  • 3,185
  • 8
  • 34
  • 66
0
votes
0 answers

Convert dynamic query result to a list in order to bind to a grid

I am using the following query in vb.net using the System.Linq.Dynamic library to bind the result to a gridview Dim customers = model.Customers _ .OrderBy(sortExp + " " + sortOrder) _ .Select("new (CustomerID, CompanyName, ContactName,…
Kuv Patel
  • 20
  • 5
0
votes
1 answer

Linq Dynamic Error with Dynamic Where clause

I have a four dropdownlists that are used to filter/order a gridview. If any of the first 3 dropdowns have a selected value other than 0 the the WhereFlag is set to True. The fourth dropdown is used to dictate which column the grid is ordered by. My…
Mych
  • 2,527
  • 4
  • 36
  • 65
0
votes
1 answer

Dynamic Linq Select -How to extract the results

I have a dynamic Linq Select statement of the form var projection = result.AsQueryable().Select(string.Format("new({0},{1})", model.XtabRow, model.XtabColumn)); This works fine and produces an IQueryable of Anonymous types. However I an…
josephj1989
  • 9,509
  • 9
  • 48
  • 70