Export (0) Print
Expand All

DbExpression Class

Implements the basic functionality required by expression types.

System.Object
  System.Data.Common.CommandTrees.DbExpression
    More...

Namespace:  System.Data.Common.CommandTrees
Assembly:  System.Data.Entity (in System.Data.Entity.dll)

public abstract class DbExpression

The DbExpression type exposes the following members.

  NameDescription
Public propertyExpressionKindGets the kind of the expression, which indicates the operation of this expression.
Public propertyResultTypeGets the type metadata for the result type of the expression.
Top

  NameDescription
Public methodAccept(DbExpressionVisitor)Implements the visitor pattern for expressions that do not produce a result value.
Public methodAccept<TResultType>(DbExpressionVisitor<TResultType>)Implements the visitor pattern for expressions that produce a result value of a specific type.
Public methodEqualsDetermines whether the specified Object is equal to the current DbExpression instance. (Overrides Object.Equals(Object).)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for the type. (Overrides Object.GetHashCode().)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

An expression is the fundamental building block of queries represented by a command tree. An expression represents some computation. Examples of expressions include constants, variables, functions, constructors, and standard relational operators like filter, join, and so on.

Every expression has a data type that designates the type of the result produced by that expression. The data type of the expression cannot be changed after creation.

An expression belongs to exactly one DbCommandTree. All sub-expressions of an expression must belong to the same DbCommandTree.

Expression trees are partially mutable: expression sub-trees can be replaced as long as the replacements have the same data type. The phrase expression sub-tree refers to the linkages between expressions.

The following snippets demonstrate what you can do with DbExpression.

This snippet uses WHERE to find all customers whose contact title is Sales Representative

public void CQTs1() {
   EntitySet customersSet = context.MetadataWorkspace.GetEntityContainer("NorthwindEntities", DataSpace.CSpace).GetEntitySetByName("Customers", false);

   DbExpression queryTree = customersSet.Scan().Where(c => c.Property("ContactTitle").Equal("Sales Representative"));

   Output.Write(queryTree);
}

This snippet projects multiple properties--each beverage's name and UnitPrice property.

public void CQTsTesting4() {
   EntitySet productsSet = context.MetadataWorkspace.GetEntityContainer("NorthwindEntities", DataSpace.CSpace).GetEntitySetByName("Products", false);

   DbExpression queryTree = productsSet.Scan()
   .Where(c => c.Property("Category").Property("CategoryName").Equal("Beverages"))
.Select(p => new Row(p.Property("ProductName").As("Name"), p.Property("UnitPrice").As("Price")));

   Output.Write(queryTree);
}

This snippet uses OfType to select DiscontinuedProducts from ProductsSet.

public void CQTsTesting5() {
   TypeUsage discontinuedProductsUsage = TypeUsage.CreateDefaultTypeUsage(context.MetadataWorkspace.GetType("DiscontinuedProduct", "NorthwindEFModel", false, DataSpace.CSpace));

EntitySet productsSet = context.MetadataWorkspace.GetEntityContainer("NorthwindEntities", DataSpace.CSpace).GetEntitySetByName("Products", false);

DbExpression queryTree = productsSet.Scan().OfType(discontinuedProductsUsage);

   Output.Write(queryTree);
}

.NET Framework

Supported in: 4, 3.5 SP1

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

System.Object
  System.Data.Common.CommandTrees.DbExpression
    System.Data.Common.CommandTrees.DbApplyExpression
    System.Data.Common.CommandTrees.DbArithmeticExpression
    System.Data.Common.CommandTrees.DbBinaryExpression
    System.Data.Common.CommandTrees.DbCaseExpression
    System.Data.Common.CommandTrees.DbConstantExpression
    System.Data.Common.CommandTrees.DbCrossJoinExpression
    System.Data.Common.CommandTrees.DbFilterExpression
    System.Data.Common.CommandTrees.DbFunctionExpression
    System.Data.Common.CommandTrees.DbGroupByExpression
    System.Data.Common.CommandTrees.DbJoinExpression
    System.Data.Common.CommandTrees.DbLambdaExpression
    System.Data.Common.CommandTrees.DbLikeExpression
    System.Data.Common.CommandTrees.DbLimitExpression
    System.Data.Common.CommandTrees.DbNewInstanceExpression
    System.Data.Common.CommandTrees.DbNullExpression
    System.Data.Common.CommandTrees.DbParameterReferenceExpression
    System.Data.Common.CommandTrees.DbProjectExpression
    System.Data.Common.CommandTrees.DbPropertyExpression
    System.Data.Common.CommandTrees.DbQuantifierExpression
    System.Data.Common.CommandTrees.DbRelationshipNavigationExpression
    System.Data.Common.CommandTrees.DbScanExpression
    System.Data.Common.CommandTrees.DbSkipExpression
    System.Data.Common.CommandTrees.DbSortExpression
    System.Data.Common.CommandTrees.DbUnaryExpression
    System.Data.Common.CommandTrees.DbVariableReferenceExpression

Community Additions

ADD
Show:
© 2015 Microsoft