ObjectContext.ExecuteStoreQuery<TElement> Method (String, Object)
Executes a query directly against the data source that returns a sequence of typed results.
Assembly: System.Data.Entity (in System.Data.Entity.dll)
public ObjectResult<TElement> ExecuteStoreQuery<TElement>( string commandText, params Object parameters )
- Type: System.String
The command to execute, in the native language of the data source.
- Type: System.Object
An array of parameters to pass to the command.
Return ValueType: System.Data.Objects.ObjectResult<>
An enumeration of objects of type TResult.
The ExecuteStoreQuery method uses the existing connection to execute an arbitrary command directly against the data source. The store command is executed in the context of the current transaction, if such a transaction exists.
Calling the ExecuteStoreQuery method is equivalent to calling the ExecuteReader method of the DbCommand class, only ExecuteStoreQuery returns entities and the ExecuteReader returns property values in the DbDataReader.
Call the ExecuteStoreQuery with the specified entity set name, if you want for the results to be tracked.
Using parameterized commands helps guard against SQL injection attacks, in which an attacker "injects" a command into a SQL statement that compromises security on the server. Parameterized commands guard against a SQL injection attack by guaranteeing that values received from an external source are passed as values only, and not part of the SQL statement. As a result, SQL commands inserted into a value are not executed at the data source. Rather, they are evaluated only as a parameter value. In addition to the security benefits, parameterized commands provide a convenient method for organizing values passed with a SQL statement or to a stored procedure.
The parameters value can be an array of DbParameter objects or an array of parameter values. If only values are supplied, an array of DbParameter objects are created based on the order of the values in the array.
For more information, see:
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.