Data Access has been discontinued. Please refer to this page for more information.

LINQ Expressions - Overview

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. A simple name 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 which parameters are in turn other method calls. Therefore, expressions can range from simple to very complex.

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

using ( FluentModel dbContext = new FluentModel() )
{
   IQueryable<int> products = from product in dbContext.Products
                              where product.UnitPrice > 20
                              select product.ProductID;
   foreach ( int id in products )
   {
       Console.WriteLine( id );
   }
}
Using dbContext As New FluentModel()
 Dim products As IQueryable(Of Integer) = From product In dbContext.Products
                                          Where product.UnitPrice > 20
                                          Select product.ProductID
 For Each id As Integer In products
  Console.WriteLine(id)
 Next id
End Using

In This Section