Share via


ObjectContext.ExecuteStoreQuery Method

Definition

Overloads

ExecuteStoreQuery<TElement>(String, String, MergeOption, Object[])

Executes a query directly against the data source and returns a sequence of typed results. The query is specified using the server's native query language, such as SQL. If an entity set name is specified, results are tracked by the context.

As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter. context.ExecuteStoreQuery<Post>("SELECT * FROM dbo.Posts WHERE Author = @p0", userSuppliedAuthor); Alternatively, you can also construct a DbParameter and supply it to SqlQuery. This allows you to use named parameters in the SQL query string. context.ExecuteStoreQuery<Post>("SELECT * FROM dbo.Posts WHERE Author = @author", new SqlParameter("@author", userSuppliedAuthor));

ExecuteStoreQuery<TElement>(String, String, ExecutionOptions, Object[])

Executes a query directly against the data source and returns a sequence of typed results. The query is specified using the server's native query language, such as SQL. If an entity set name is specified, results are tracked by the context.

As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter. context.ExecuteStoreQuery<Post>("SELECT * FROM dbo.Posts WHERE Author = @p0", userSuppliedAuthor); Alternatively, you can also construct a DbParameter and supply it to SqlQuery. This allows you to use named parameters in the SQL query string. context.ExecuteStoreQuery<Post>("SELECT * FROM dbo.Posts WHERE Author = @author", new SqlParameter("@author", userSuppliedAuthor));

ExecuteStoreQuery<TElement>(String, Object[])

Executes a query directly against the data source and returns a sequence of typed results. The query is specified using the server's native query language, such as SQL. Results are not tracked by the context, use the overload that specifies an entity set name to track results.

As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter. context.ExecuteStoreQuery<Post>("SELECT * FROM dbo.Posts WHERE Author = @p0", userSuppliedAuthor); Alternatively, you can also construct a DbParameter and supply it to SqlQuery. This allows you to use named parameters in the SQL query string. context.ExecuteStoreQuery<Post>("SELECT * FROM dbo.Posts WHERE Author = @author", new SqlParameter("@author", userSuppliedAuthor));

ExecuteStoreQuery<TElement>(String, ExecutionOptions, Object[])

Executes a query directly against the data source and returns a sequence of typed results. The query is specified using the server's native query language, such as SQL. Results are not tracked by the context, use the overload that specifies an entity set name to track results.

As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter. context.ExecuteStoreQuery<Post>("SELECT * FROM dbo.Posts WHERE Author = @p0", userSuppliedAuthor); Alternatively, you can also construct a DbParameter and supply it to SqlQuery. This allows you to use named parameters in the SQL query string. context.ExecuteStoreQuery<Post>("SELECT * FROM dbo.Posts WHERE Author = @author", new SqlParameter("@author", userSuppliedAuthor));

ExecuteStoreQuery<TElement>(String, String, MergeOption, Object[])

Executes a query directly against the data source and returns a sequence of typed results. The query is specified using the server's native query language, such as SQL. If an entity set name is specified, results are tracked by the context.

As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter. context.ExecuteStoreQuery<Post>("SELECT * FROM dbo.Posts WHERE Author = @p0", userSuppliedAuthor); Alternatively, you can also construct a DbParameter and supply it to SqlQuery. This allows you to use named parameters in the SQL query string. context.ExecuteStoreQuery<Post>("SELECT * FROM dbo.Posts WHERE Author = @author", new SqlParameter("@author", userSuppliedAuthor));

public virtual System.Data.Entity.Core.Objects.ObjectResult<TElement> ExecuteStoreQuery<TElement> (string commandText, string entitySetName, System.Data.Entity.Core.Objects.MergeOption mergeOption, params object[] parameters);
abstract member ExecuteStoreQuery : string * string * System.Data.Entity.Core.Objects.MergeOption * obj[] -> System.Data.Entity.Core.Objects.ObjectResult<'Element>
override this.ExecuteStoreQuery : string * string * System.Data.Entity.Core.Objects.MergeOption * obj[] -> System.Data.Entity.Core.Objects.ObjectResult<'Element>

Type Parameters

TElement

The element type of the result sequence.

Parameters

commandText
String

The query specified in the server's native query language.

entitySetName
String

The entity set of the TResult type. If an entity set name is not provided, the results are not going to be tracked.

mergeOption
MergeOption

The MergeOption to use when executing the query. The default is AppendOnly.

parameters
Object[]

The parameter values to use for the query. If output parameters are used, their values will not be available until the results have been read completely. This is due to the underlying behavior of DbDataReader, see http://go.microsoft.com/fwlink/?LinkID=398589 for more details.

Returns

ObjectResult<TElement>

An enumeration of objects of type TElement .

Applies to

ExecuteStoreQuery<TElement>(String, String, ExecutionOptions, Object[])

Executes a query directly against the data source and returns a sequence of typed results. The query is specified using the server's native query language, such as SQL. If an entity set name is specified, results are tracked by the context.

As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter. context.ExecuteStoreQuery<Post>("SELECT * FROM dbo.Posts WHERE Author = @p0", userSuppliedAuthor); Alternatively, you can also construct a DbParameter and supply it to SqlQuery. This allows you to use named parameters in the SQL query string. context.ExecuteStoreQuery<Post>("SELECT * FROM dbo.Posts WHERE Author = @author", new SqlParameter("@author", userSuppliedAuthor));

public virtual System.Data.Entity.Core.Objects.ObjectResult<TElement> ExecuteStoreQuery<TElement> (string commandText, string entitySetName, System.Data.Entity.Core.Objects.ExecutionOptions executionOptions, params object[] parameters);
abstract member ExecuteStoreQuery : string * string * System.Data.Entity.Core.Objects.ExecutionOptions * obj[] -> System.Data.Entity.Core.Objects.ObjectResult<'Element>
override this.ExecuteStoreQuery : string * string * System.Data.Entity.Core.Objects.ExecutionOptions * obj[] -> System.Data.Entity.Core.Objects.ObjectResult<'Element>

Type Parameters

TElement

The element type of the result sequence.

Parameters

commandText
String

The query specified in the server's native query language.

entitySetName
String

The entity set of the TResult type. If an entity set name is not provided, the results are not going to be tracked.

executionOptions
ExecutionOptions

The options for executing this query.

parameters
Object[]

The parameter values to use for the query. If output parameters are used, their values will not be available until the results have been read completely. This is due to the underlying behavior of DbDataReader, see http://go.microsoft.com/fwlink/?LinkID=398589 for more details.

Returns

ObjectResult<TElement>

An enumeration of objects of type TElement .

Applies to

ExecuteStoreQuery<TElement>(String, Object[])

Executes a query directly against the data source and returns a sequence of typed results. The query is specified using the server's native query language, such as SQL. Results are not tracked by the context, use the overload that specifies an entity set name to track results.

As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter. context.ExecuteStoreQuery<Post>("SELECT * FROM dbo.Posts WHERE Author = @p0", userSuppliedAuthor); Alternatively, you can also construct a DbParameter and supply it to SqlQuery. This allows you to use named parameters in the SQL query string. context.ExecuteStoreQuery<Post>("SELECT * FROM dbo.Posts WHERE Author = @author", new SqlParameter("@author", userSuppliedAuthor));

public virtual System.Data.Entity.Core.Objects.ObjectResult<TElement> ExecuteStoreQuery<TElement> (string commandText, params object[] parameters);
abstract member ExecuteStoreQuery : string * obj[] -> System.Data.Entity.Core.Objects.ObjectResult<'Element>
override this.ExecuteStoreQuery : string * obj[] -> System.Data.Entity.Core.Objects.ObjectResult<'Element>
Public Overridable Function ExecuteStoreQuery(Of TElement) (commandText As String, ParamArray parameters As Object()) As ObjectResult(Of TElement)

Type Parameters

TElement

The element type of the result sequence.

Parameters

commandText
String

The query specified in the server's native query language.

parameters
Object[]

The parameter values to use for the query. If output parameters are used, their values will not be available until the results have been read completely. This is due to the underlying behavior of DbDataReader, see http://go.microsoft.com/fwlink/?LinkID=398589 for more details.

Returns

ObjectResult<TElement>

An enumeration of objects of type TElement .

Applies to

ExecuteStoreQuery<TElement>(String, ExecutionOptions, Object[])

Executes a query directly against the data source and returns a sequence of typed results. The query is specified using the server's native query language, such as SQL. Results are not tracked by the context, use the overload that specifies an entity set name to track results.

As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter. context.ExecuteStoreQuery<Post>("SELECT * FROM dbo.Posts WHERE Author = @p0", userSuppliedAuthor); Alternatively, you can also construct a DbParameter and supply it to SqlQuery. This allows you to use named parameters in the SQL query string. context.ExecuteStoreQuery<Post>("SELECT * FROM dbo.Posts WHERE Author = @author", new SqlParameter("@author", userSuppliedAuthor));

public virtual System.Data.Entity.Core.Objects.ObjectResult<TElement> ExecuteStoreQuery<TElement> (string commandText, System.Data.Entity.Core.Objects.ExecutionOptions executionOptions, params object[] parameters);
abstract member ExecuteStoreQuery : string * System.Data.Entity.Core.Objects.ExecutionOptions * obj[] -> System.Data.Entity.Core.Objects.ObjectResult<'Element>
override this.ExecuteStoreQuery : string * System.Data.Entity.Core.Objects.ExecutionOptions * obj[] -> System.Data.Entity.Core.Objects.ObjectResult<'Element>

Type Parameters

TElement

The element type of the result sequence.

Parameters

commandText
String

The query specified in the server's native query language.

executionOptions
ExecutionOptions

The options for executing this query.

parameters
Object[]

The parameter values to use for the query. If output parameters are used, their values will not be available until the results have been read completely. This is due to the underlying behavior of DbDataReader, see http://go.microsoft.com/fwlink/?LinkID=398589 for more details.

Returns

ObjectResult<TElement>

An enumeration of objects of type TElement .

Applies to