Bewerken

Share via


ObjectContext.ExecuteFunction Method

Definition

Overloads

ExecuteFunction(String, ObjectParameter[])

Executes a stored procedure or function that is defined in the data source and expressed in the conceptual model; discards any results returned from the function; and returns the number of rows affected by the execution.

ExecuteFunction<TElement>(String, ObjectParameter[])

Executes a stored procedure or function that is defined in the data source and mapped in the conceptual model, with the specified parameters. Returns a typed ObjectResult<T>.

ExecuteFunction<TElement>(String, MergeOption, ObjectParameter[])

Executes the given stored procedure or function that is defined in the data source and expressed in the conceptual model, with the specified parameters, and merge option. Returns a typed ObjectResult<T>.

ExecuteFunction(String, ObjectParameter[])

Executes a stored procedure or function that is defined in the data source and expressed in the conceptual model; discards any results returned from the function; and returns the number of rows affected by the execution.

public:
 int ExecuteFunction(System::String ^ functionName, ... cli::array <System::Data::Objects::ObjectParameter ^> ^ parameters);
public int ExecuteFunction (string functionName, params System.Data.Objects.ObjectParameter[] parameters);
member this.ExecuteFunction : string * System.Data.Objects.ObjectParameter[] -> int
Public Function ExecuteFunction (functionName As String, ParamArray parameters As ObjectParameter()) As Integer

Parameters

functionName
String

The name of the stored procedure or function. The name can include the container name, such as <Container Name>.<Function Name>. When the default container name is known, only the function name is required.

parameters
ObjectParameter[]

An array of ObjectParameter objects.

Returns

The number of rows affected.

Exceptions

function is null or empty

-or-

function is not found.

The entity reader does not support this function.

-or-

There is a type mismatch on the reader and the function.

Applies to

ExecuteFunction<TElement>(String, ObjectParameter[])

Executes a stored procedure or function that is defined in the data source and mapped in the conceptual model, with the specified parameters. Returns a typed ObjectResult<T>.

protected:
generic <typename TElement>
 where TElement : System::Data::Objects::DataClasses::IEntityWithChangeTracker System::Data::Objects::ObjectResult<TElement> ^ ExecuteFunction(System::String ^ functionName, ... cli::array <System::Data::Objects::ObjectParameter ^> ^ parameters);
public:
generic <typename TElement>
 System::Data::Objects::ObjectResult<TElement> ^ ExecuteFunction(System::String ^ functionName, ... cli::array <System::Data::Objects::ObjectParameter ^> ^ parameters);
protected System.Data.Objects.ObjectResult<TElement> ExecuteFunction<TElement> (string functionName, params System.Data.Objects.ObjectParameter[] parameters) where TElement : System.Data.Objects.DataClasses.IEntityWithChangeTracker;
public System.Data.Objects.ObjectResult<TElement> ExecuteFunction<TElement> (string functionName, params System.Data.Objects.ObjectParameter[] parameters);
member this.ExecuteFunction : string * System.Data.Objects.ObjectParameter[] -> System.Data.Objects.ObjectResult<'Element (requires 'Element :> System.Data.Objects.DataClasses.IEntityWithChangeTracker)> (requires 'Element :> System.Data.Objects.DataClasses.IEntityWithChangeTracker)
member this.ExecuteFunction : string * System.Data.Objects.ObjectParameter[] -> System.Data.Objects.ObjectResult<'Element>
Protected Function ExecuteFunction(Of TElement As IEntityWithChangeTracker) (functionName As String, ParamArray parameters As ObjectParameter()) As ObjectResult(Of TElement)
Public Function ExecuteFunction(Of TElement) (functionName As String, ParamArray parameters As ObjectParameter()) As ObjectResult(Of TElement)

Type Parameters

TElement

The entity type of the ObjectResult<T> returned when the function is executed against the data source. This type must implement IEntityWithChangeTracker.

Parameters

functionName
String

The name of the stored procedure or function. The name can include the container name, such as <Container Name>.<Function Name>. When the default container name is known, only the function name is required.

parameters
ObjectParameter[]

An array of ObjectParameter objects.

Returns

ObjectResult<TElement>

An ObjectResult<T> for the data that is returned by the stored procedure.

Exceptions

function is null or empty

-or-

function is not found.

The entity reader does not support this function.

-or-

There is a type mismatch on the reader and the function.

Remarks

The ExecuteFunction method is a helper method that is used to execute stored procedures or functions that are defined in the data source and expressed in the conceptual model. The Entity Data Model tools generate a method for each FunctionImport Element in the conceptual model. These methods call a strongly-typed ExecuteFunction to return a typed ObjectResult<T>. For more information, see Application Code using Stored Procedures (Entity Framework).

All parameters for the function are required in the parameters array and all types are checked against the metadata for the import function, including the type of the function itself. null values are permitted for CLR value types. Parameter validation is performed by the provider.

The ExecuteFunction method uses the MergeOption value of AppendOnly. Therefore, if an object already exists in the object context, it will not be loaded from the data source.

See also

Applies to

ExecuteFunction<TElement>(String, MergeOption, ObjectParameter[])

Executes the given stored procedure or function that is defined in the data source and expressed in the conceptual model, with the specified parameters, and merge option. Returns a typed ObjectResult<T>.

public:
generic <typename TElement>
 System::Data::Objects::ObjectResult<TElement> ^ ExecuteFunction(System::String ^ functionName, System::Data::Objects::MergeOption mergeOption, ... cli::array <System::Data::Objects::ObjectParameter ^> ^ parameters);
public System.Data.Objects.ObjectResult<TElement> ExecuteFunction<TElement> (string functionName, System.Data.Objects.MergeOption mergeOption, params System.Data.Objects.ObjectParameter[] parameters);
member this.ExecuteFunction : string * System.Data.Objects.MergeOption * System.Data.Objects.ObjectParameter[] -> System.Data.Objects.ObjectResult<'Element>
Public Function ExecuteFunction(Of TElement) (functionName As String, mergeOption As MergeOption, ParamArray parameters As ObjectParameter()) As ObjectResult(Of TElement)

Type Parameters

TElement

The entity type of the ObjectResult<T> returned when the function is executed against the data source. This type must implement IEntityWithChangeTracker.

Parameters

functionName
String

The name of the stored procedure or function. The name can include the container name, such as <Container Name>.<Function Name>. When the default container name is known, only the function name is required.

mergeOption
MergeOption

The MergeOption to use when executing the query.

parameters
ObjectParameter[]

An array of ObjectParameter objects.

Returns

ObjectResult<TElement>

An ObjectResult<T> for the data that is returned by the stored procedure.

Exceptions

function is null or empty

-or-

function is not found.

The entity reader does not support this function.

-or-

There is a type mismatch on the reader and the function.

Remarks

The ExecuteFunction method is a helper method that is used to execute stored procedures or functions that are defined in the data source and expressed in conceptual model. The Entity Data Model tools generate a method for each FunctionImport Element in the conceptual model. These methods call a strongly-typed ExecuteFunction to return a typed ObjectResult<T>. For more information, see Application Code using Stored Procedures (Entity Framework).

All parameters for the function are required in the parameters array and all types are checked against the metadata for the import function, including the type of the function itself. null values are permitted for CLR value types. Parameter validation is performed by the provider.

See also

Applies to