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 can I use Dynamic Linq to project sub collections?

I know how to get Dynamic Linq to project sub (non-collection) objects, e.g. "new(new(CustomerStat.ID) as CustomerStat)", where CustomerStat is a non-collection object. I'd like to do the something similar with collections, e.g. "new(LocationId,…
Giovanni Galbo
  • 12,963
  • 13
  • 59
  • 78
0
votes
2 answers

dynamic query using expression tree

I have a form in which the user will choose the following from dropdown lists: table_name columnName_to_sort_by columnName_to_search_in The user shall enter Search_text in a text box The form shall draw data from many tables. I want to avoid…
0
votes
2 answers

Foreach Dynamic Linq Multiple Columns

Hello I'm using dynamic linq and I have query like this one: var result = DataContext.Table .Where("Code == @0", CodeId) .Select("new(SGL AS First, DBL AS Second)"); How can I loop the result? I'm using something like this code but it…
Luis Lora
  • 83
  • 1
  • 9
0
votes
1 answer

Dynamic Linq and use of Between

I am having a Dynamic Linq where It should perform comparison between two integers. I tried so many but none of them worked for me. Code db.Bibs.Where(" Id >= 1 && Id<1000 ") db.Bibs.Where(" Id between 1 && 1000 ") How to form this string to make…
DonMax
  • 970
  • 3
  • 12
  • 47
0
votes
0 answers

Linq/Dynamic Linq orderby first column (or primary key)

I've written a grid component and I've decided to make having no sortable columns (on the grid) an option. Serverside, my query does pagination using .Skip and looks similar to this public object PaginateQueryAsJson(TQuery query) …
Slight
  • 1,541
  • 3
  • 19
  • 38
0
votes
1 answer

Dynamic Linq Library can't handling one on many relationship in select clause

I would like to get records from the database using Dynamic Linq Library NuGet. How can I write query for select parent records along with list of child records. For example there is One-on-Many relationship between Question and Answers table.…
sridharnetha
  • 2,104
  • 8
  • 35
  • 69
0
votes
1 answer

How to execute a LINQ to Entities query, pulling values from an existing resultset variable instead of against the DB

To provide some context, I'm using jqGrid to conduct a server side search on a datetime field, truncating the time portion server side, and then fetching results via a stored procedure. This is being done using System.Dynamic.Linq, which I've…
RizJa
  • 1,961
  • 1
  • 21
  • 38
0
votes
2 answers

OrderBy with Dynamic Linq

I am trying to sort some data from entity before passing them to another function. Both tableName and columnName are selected dynamically. This is what I'm doing: string tableName = cboSelectTable.Text.ToString(); var comboBoxColumn = from a in…
Paradox
  • 129
  • 1
  • 3
  • 14
0
votes
1 answer

Expression of type 'T' expected when using Dynamic Linq

I'm using the Dynamic Linq Library in my .NET MVC application to query a SQL Server database. It's all working fine so far. I need to make a dynamic select but always return Expression of type 'T' expected: public static IQueryable
0
votes
1 answer

Dynamic Linq to OrderBy Object Nested in IEnumerable

I am trying to write some dynamic linq to order by a property of a list item, for use with NHibernate public class Company { public string Name { get; set; } public List Employees { get; set; } } public class Employee { public…
0
votes
0 answers

LINQ group by dynamic

I am trying to make a dynamic grouping for LINQ and I am just not getting the syntax correct. Any help would be greatly appreciated. Here is my static LINQ code; var query = from x in myCollection group x by x.Field1 into g select new…
Xaphann
  • 3,195
  • 10
  • 42
  • 70
0
votes
1 answer

Dynamic linq query is not working with numeric value

This is my code: // Taken from combobox selection. string columnName = cboCrudSearchColumn.Text.ToString(); // Taken from textbox selection. string searchValue = txtCrudSearch.Text.ToString(); dgvLoadTable.DataSource = EntityName .TableName …
Paradox
  • 129
  • 1
  • 3
  • 14
0
votes
3 answers

Formatting Select Statement Using Dynamic Linq

I've been looking into this for quite some time now and cannot figure out a resolution. I Originally Tried formatting A dynamic linq Statement as you can see here in this post I declared a class: public class DynamicHelper { public string…
johnny 5
  • 19,893
  • 50
  • 121
  • 195
0
votes
1 answer

Dynamic Linq Execute Functions inside of Select Statement

I'm trying to grab out formatted values from a project. I have a function declared: public static string GetFormattedLink(string ExtTitleID) { return "Str_" + ExtTitleID; } How would I execute this statement from the Select Statement in Dynamic…
johnny 5
  • 19,893
  • 50
  • 121
  • 195
0
votes
1 answer

Dynamic Linq queries with sorting, nulls at end

I am trying to build an ASP.NET page that sorts on nullable fields. What I want to do is, if there are null values in the sortable field, always throw those rows to the end of the list. Otherwise, they show up at the beginning of the list, and I can…
mmelear
  • 97
  • 11