DbExpression Class
Implements the basic functionality required by expression types.
Assembly: System.Data.Entity (in System.Data.Entity.dll)
The DbExpression type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | ExpressionKind | Gets the kind of the expression, which indicates the operation of this expression. |
![]() | ResultType | Gets the type metadata for the result type of the expression. |
| Name | Description | |
|---|---|---|
![]() | Accept(DbExpressionVisitor) | Implements the visitor pattern for expressions that do not produce a result value. |
![]() | Accept<TResultType>(DbExpressionVisitor<TResultType>) | Implements the visitor pattern for expressions that produce a result value of a specific type. |
![]() | Equals | Determines whether the specified Object is equal to the current DbExpression instance. (Overrides Object::Equals(Object).) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for the type. (Overrides Object::GetHashCode().) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
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);
}
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.
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
