DbExpressionBuilder.New Method (TypeUsage, IEnumerable<DbExpression>)

.NET Framework (current version)
 

Creates a new DbNewInstanceExpression. If the type argument is a collection type, the arguments specify the elements of the collection. Otherwise the arguments are used as property or column values in the new instance.

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

public static DbNewInstanceExpression New(
	this TypeUsage instanceType,
	IEnumerable<DbExpression> arguments
)

Parameters

instanceType
Type: System.Data.Metadata.Edm.TypeUsage

The type of the new instance.

arguments
Type: System.Collections.Generic.IEnumerable<DbExpression>

Expressions that specify values of the new instances, interpreted according to the instance's type.

Return Value

Type: System.Data.Common.CommandTrees.DbNewInstanceExpression

A new DbNewInstanceExpression with the specified type and arguments.

Exception Condition
ArgumentNullException

instanceType or arguments is null, or arguments contains null.

ArgumentException

arguments is empty or the result types of the contained expressions do not match the requirements of instanceType (as explained in the remarks section).

If instanceType is a a collection type then every expression in arguments must have a result type that is promotable to the element type of the instanceType. If instanceType is a row type, arguments must contain as many expressions as there are columns in the row type, and the result type of each expression must be equal or promotable to the type of the corresponding column. A row type that does not declare any columns is invalid. If instanceType is an entity type, arguments must contain as many expressions as there are properties defined by the type, and the result type of each expression must be equal or promotable to the type of the corresponding property.

.NET Framework
Available since 4.5
Return to top
Show: