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 do I create this expression tree (dynamic lambda) in C#?

I am trying to create an expression tree (dynamic linq) that represents the following: There are my custom classes and collections. List sel = contractList.Where(s => s.account.Age > 3 && s.productList.Any(a => a.ProductType ==…
Jose
  • 11
  • 2
0
votes
1 answer

Make a dynamic query with Linq using a drop down list selected option in Asp.net MVC

I'm trying to accomplish this with Linq to Sql and Asp.Net MVC: I have a Drop Down List with options Country, City and State. And beside it, there is a textbox. So, an user will, for instance, select City and will type "new york city" in the…
André Miranda
  • 6,420
  • 20
  • 70
  • 94
0
votes
3 answers

How to add an AND/OR expression to the following dynamic linq expression

T is a type that may or may not have a specific property, lets say 'City'. For the types that have a property named 'City', I would like to restrict the records such that only residents of the Gotham are returned and they are sorted. public static…
WPFAbsoluteNewBie
  • 1,285
  • 2
  • 10
  • 21
0
votes
2 answers

How to get Lambda in LINQ to actually filter for dynamic linq

Example-I have a person class Public Class Person Private _fname As String Public Property Fname() As String Get Return _fname End Get Set(ByVal value As String) _fname = value End Set End Property Private _lname As…
Eric
  • 3,027
  • 6
  • 29
  • 34
0
votes
1 answer

Dynamic expression parsing in localized environment

So I'm trying to parse a simple arithmetic dynamic expression using System.Linq.Dynamic. This runs fine when executed in an English environment where the CurrentCulture is English-US (and the decimal separator is a plain "." dot). Trying to run the…
alrotem
  • 92
  • 1
  • 7
0
votes
1 answer

How would i assign distinct attribute value in a ComboBox datacontext?

I would like to show all distinct Category in a ComboBox named categoryList
arefinsami
  • 363
  • 2
  • 7
  • 18
0
votes
1 answer

Dynamic Linq Datetime where

im using dynamic linq in order to build a query and im having an issue with DateTime queryResults- contain a list of result from a previous query . sr.FromDate- a DateTime parameter what im trying to do is to get the all the result that greater…
MIkCode
  • 2,655
  • 5
  • 28
  • 46
0
votes
2 answers

How do I merge objects back together after a SelectMany in System.Linq.Dynamic or maybe different solution all together?

I'm trying to select out a couple of fields in a collection inside of collection. Roles->Users (name and ID) I was able to get flattened data using select many, but now I need to merge it back to a collection objects so my json is formatted…
Nick Tullos
  • 511
  • 7
  • 23
0
votes
0 answers

System.Linq.Dynamic to select a collection inside of a collection from Entity Framework IQueryable

I have an EF model with the relationship User->Roles. It's a one to many relationship in our database. I would like to select the ID from role's record and the name from the user's records. What I have come up with works for one-to-one…
0
votes
2 answers

Dyamic Linq .Net 4 error 'userid' could not be resolved in the current scope or contex

I am trying to use Dynamic Linq library in my code, but it gives this error 'UserId' could not be resolved in the current scope or context. Make sure that all referenced variables are in scope, that required schemas are loaded, and that namespaces…
Waqas
  • 424
  • 7
  • 15
0
votes
1 answer

Select a listview item as object

I got a ListView control that contains a GridView control too. Data are comming from different Table from database Database scheme: Books (BookID, BookName, ISBN, CopyLeft); Borrowers (BorrowerID, BorrowerName, BorrowerLevel); Transactions…
arefinsami
  • 363
  • 2
  • 7
  • 18
0
votes
2 answers

Join multiple table and bind into a single Listview using C# .net

I got three tables to join named Books, Borrowers and Transactions. The database scheme is as…
arefinsami
  • 363
  • 2
  • 7
  • 18
0
votes
1 answer

Scott Gu Dynamic Linq Convert Datetime to ShortDatetime

I am using the Scott Gu Dynamic Linq class and I am trying to convert a datetime to return a short datetime before databinding the result set to a gridview in ASP.net. Now, I know that I can go through the gridview row databound event and check…
EvanGWatkins
  • 1,427
  • 6
  • 23
  • 52
0
votes
2 answers

Using Linq DynamicQuerable for a Not IN sql type operation

I am using the Linq DynamicQuerable code. I have an array of integers and a string representing the field I want to use as the excluding filter. For example IQuerable GetItemsWithoutExcluded(IQuerable qry, string primaryKey, List excludedItems)…
Kenoyer130
  • 6,874
  • 9
  • 51
  • 73
0
votes
1 answer

Dynamic Linq/ Dynamic Query: cannot get data for jqGrid

I'm using jqGrid and I have a problem getting Dynamic Linq to work. I used NuGet to install Dynamic and added "using System.Linq.Dynamic;". Using VS 2010 Pro, MVC 3.0 This works: var s = context.testdata; var c = s.Count(); c shows 5136 items. But…
Oliver Kötter
  • 1,006
  • 11
  • 29