Questions tagged [linq-expressions]

An API for composing code with declarative expression trees, used by LINQ and the DLR.

About

The System.Linq.Expressions namespace in .NET 3.5 and later provides an API for composing code in terms of declarative expression trees, as well as a compiler to transform top-level lambda expressions into delegates (i.e., callbacks). Originally created to facilitate the creation of custom query providers in , it has since evolved to form the basis of the .

Relationship to LINQ

The first version of System.Linq.Expressions, which shipped with .NET 3.5, was designed to model query expressions. Consequently, it supports only a subset of the expression types representable in .NET languages like C# and VB.NET. Query expressions in LINQ are processed by a query provider and, ideally, transformed into a combination of local and remote operations. The LINQ to SQL and LINQ to Entity Framework providers, for example, will attempt to transform a query expression into equivalent SQL, enabling operations like filtering, sorting, and aggregation to be performed (and optimized) by the database engine. This is particularly useful for larger data sets that would render in-memory processing impractical.

Evolution

While the System.Linq.Expressions APIs proved useful for modeling complex expressions, it lacked the control flow mechanisms necessary to model the kind of code produced by imperative programming languages. Thus, it was less useful for general-purpose code generation. This changed when Microsoft began developing its Dynamic Language Runtime (DLR), a set of common language services designed to support the development of dynamic languages.

Core aspects of the DLR include support for dynamic call sites, dynamic code generation, and language hosting. Microsoft decided to use System.Linq.Expressions as the code model for the DLR's dynamic call site and code generation infrastructure. The expression tree API and compiler were extended to support a much wider range of language constructs, most notably control flow (conditions, loops, switch statements, etc.) and exception handling. Languages like IronRuby and IronPython ultimately transform their own syntax trees into LINQ expression trees, which may then be compiled or interpreted directly by the DLR.

Developers wishing to perform runtime code generation may choose to compose code using LINQ/DLR expression trees as a more convenient and less error-prone alternative to emitting raw IL byte code.

591 questions
-1
votes
2 answers

How do I read an Expression's contents?

I have a class that works as a repository of some sort, and grants access to a database. I'm trying to customize it to allow queries with expressions. So, I want to be able to do this: IList myList = myRepository.GetBy(x => x.Name ==…
Danicco
  • 1,573
  • 2
  • 23
  • 49
-1
votes
1 answer

How to write expression tree syntax to find max base on property

Work on C# EF 4. Want to find list max information selector= entityBillax.BillTaxID public static List GetMaxRowIDForChild2(T fromList, Expression> selector) { selector = fromList.Count + 1; …
shamim
  • 6,640
  • 20
  • 85
  • 151
-1
votes
2 answers

LINQ to Entities does not recognize the method 'System.String ToBase64String(Byte[])' method,

LINQ to Entities does not recognize the method 'System.String ToBase64String(Byte[])' method, and this method cannot be translated into a store expression. var activityList = (from item in committeeMemberList let committee =…
James123
  • 11,184
  • 66
  • 189
  • 343
-1
votes
1 answer

Linq Expression on sub child entities for n levels

Need Generic expression for the below Query. I don't want to use the Dynamic library and Predicate builder. I am generating expressions dynamically. var test = entity.User.Where(PUser => PUser.Role.TeamRoles.Any(PTeamRoles => PTeamRoles.TeamId ==…
-2
votes
2 answers

how to build predicate that insensitive text search

i have one grid view search filtering facility but with one draw back. here while user searching string with collection i have to make it like insensitive contains. here is my helper method : public static IQueryable FilterForColumn(this…
Shal
  • 319
  • 4
  • 8
  • 25
-3
votes
2 answers

How can I write foreach loop to sum elements in lamba expression?

How can I write foreach loop shown below as a labmda expression? var sum = 0; foreach (SomeClass obj in SomeListOfClass) { sum += obj.SomeValue; } I am expecting a lambda expression that look like this var sum = SomeListOfClass.ForEachMethod( x…
talaa123
  • 123
  • 1
  • 2
  • 14
1 2 3
39
40