Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

Expressions in LINQ to Entities Queries

An expression is a fragment of code that can be evaluated to a single value, object, method, or namespace. Expressions can contain a literal value, a method call, an operator and its operands, or a simple name. Simple names can be the name of a variable, type member, method parameter, namespace or type. Expressions can use operators that in turn use other expressions as parameters, or method calls whose parameters are in turn other method calls. Therefore, expressions can range from simple to very complex.

In LINQ to Entities queries, expressions can contain anything allowed by the types within the System.Linq.Expressions namespace, including lambda expressions. The expressions that can be used in LINQ to Entities queries are a superset of the expressions that can be used to query the Entity Framework. Expressions that are part of queries against the Entity Framework are limited to operations supported by ObjectQuery<T> and the underlying data source. 

In the following example, the comparison in the Where clause is an expression:

Decimal totalDue = 200;
using (AdventureWorksEntities context = new AdventureWorksEntities())
{
    IQueryable<int> salesInfo =
        from s in context.SalesOrderHeaders
        where s.TotalDue >= totalDue
        select s.SalesOrderID;

    Console.WriteLine("Sales order info:");
    foreach (int orderNumber in salesInfo)
    {
        Console.WriteLine("Order number: " + orderNumber);                    
    }
}

Bb738645.note(en-us,VS.100).gifNote:
Specific language constructs, such as C# unchecked, have no meaning in LINQ to Entities.

In This Section

See Also

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.