DbExpressionBuilder.Join<TSelector> Method (DbExpression, DbExpression, Func<DbExpression, DbExpression>, Func<DbExpression, DbExpression>, Func<DbExpression, DbExpression, TSelector>)

.NET Framework (current version)
 

Creates a new DbProjectExpression that projects the specified selector over the sets specified by the outer and inner expressions, joined on an equality condition between the specified outer and inner keys, using InnerJoin as the DbExpressionKind.

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

public static DbProjectExpression Join<TSelector>(
	this DbExpression outer,
	DbExpression inner,
	Func<DbExpression, DbExpression> outerKey,
	Func<DbExpression, DbExpression> innerKey,
	Func<DbExpression, DbExpression, TSelector> selector
)

Parameters

outer
Type: System.Data.Common.CommandTrees.DbExpression

A DbExpression that specifies the outer set argument.

inner
Type: System.Data.Common.CommandTrees.DbExpression

A DbExpression that specifies the inner set argument.

outerKey
Type: System.Func<DbExpression, DbExpression>

A method that specifies how the outer key value should be derived from an element of the outer set.

innerKey
Type: System.Func<DbExpression, DbExpression>

A method that specifies how the inner key value should be derived from an element of the inner set.

selector
Type: System.Func<DbExpression, DbExpression, TSelector>

A method that specifies how an element of the result set should be derived from elements of the inner and outer sets. This method must produce an instance of a type that is compatible with Join and can be resolved into a DbExpression. Compatibility requirements for TSelector are described in remarks.

Return Value

Type: System.Data.Common.CommandTrees.DbProjectExpression

A new DbProjectExpression with the specified selector as its projection, and a new DbJoinExpression as its input. The input DbJoinExpression is created with an DbExpressionKind of InnerJoin, that represents the inner join operation applied to the left and right input sets under a join condition that compares the outer and inner key values for equality.

Type Parameters

TSelector

The type of the selector.

Exception Condition
ArgumentNullException

outer, inner, outerKey, innerKey or selector is null.

ArgumentException

outer or inner does not have a collection result type.

ArgumentNullException

The expression produced by outerKey or innerKey is null.

ArgumentNullException

The result of selector is null after conversion to DbExpression.

ArgumentException

The expressions produced by outerKey and innerKey is not comparable for equality.

ArgumentException

The result of Selector is not compatible with SelectMany.

To be compatible with Join, TSelector must be derived from DbExpression, or must be an anonymous type with DbExpression-derived properties. The following are examples of supported types for TSelector:

outer.Join(inner, o => o.Property("ID"), i => i.Property("ID"), (o, i) => o.Property("Name"))

(TSelector is DbPropertyExpression).

outer.Join(inner, o => o.Property("ID"), i => i.Property("ID"), (o, i) => new { OName = o.Property("Name"), IName = i.Property("Name") })

(TSelector is an anonymous type with DbExpression-derived properties).

.NET Framework
Available since 4.5
Return to top
Show: