ObjectContext.ExecuteStoreQuery ObjectContext.ExecuteStoreQuery ObjectContext.ExecuteStoreQuery ObjectContext.ExecuteStoreQuery Method

定義

多載

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

直接針對資料來源執行查詢,並傳回具型別的結果序列。Executes a query directly against the data source that returns a sequence of typed results.

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

直接針對資料來源執行查詢,並傳回具型別的結果序列。Executes a query directly against the data source and returns a sequence of typed results. 指定實體集和合併選項,以便能夠以實體形式追蹤查詢結果。Specify the entity set and the merge option so that query results can be tracked as entities.

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

直接針對資料來源執行查詢,並傳回具型別的結果序列。Executes a query directly against the data source that returns a sequence of typed results.

public:
generic <typename TElement>
 System::Data::Objects::ObjectResult<TElement> ^ ExecuteStoreQuery(System::String ^ commandText, ... cli::array <System::Object ^> ^ parameters);
public System.Data.Objects.ObjectResult<TElement> ExecuteStoreQuery<TElement> (string commandText, params object[] parameters);
member this.ExecuteStoreQuery : string * obj[] -> System.Data.Objects.ObjectResult<'Element>
Public Function ExecuteStoreQuery(Of TElement) (commandText As String, ParamArray parameters As Object()) As ObjectResult(Of TElement)

類型參數

TElement

傳回之資料的型別。The type of the returned data.

參數

commandText
String String String String

要使用資料來源的原生語言來執行之命令。The command to execute, in the native language of the data source.

parameters
Object[]

要傳遞至命令的參數陣列。An array of parameters to pass to the command.

傳回

ObjectResult<TElement>

型別為 TElement 之物件的列舉。An enumeration of objects of type TElement.

備註

ExecuteStoreQuery方法會使用現有的連接來執行任意命令直接針對資料來源。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.

呼叫 ExecuteStoreQuery 方法相當於呼叫 ExecuteReader 類別的 DbCommand 方法,只有 ExecuteStoreQuery 會傳回實體,而 ExecuteReader 會傳回 DbDataReader 中的屬性值。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.

呼叫ExecuteStoreQuery與指定之實體集名稱,如果您想要追蹤的結果。Call the ExecuteStoreQuery with the specified entity set name, if you want for the results to be tracked.

呼叫Translate方法來轉譯DbDataReader為實體物件時讀取器包含對應至指定的實體類型的資料列。Call the Translate method to translate a DbDataReader into entity objects when the reader contains data rows that map to the specified entity type.

使用參數型命令 (Parameterized Command) 有助於防衛 SQL 插入式攻擊,在此類攻擊中,攻擊者會將命令「插入」至 SQL 陳述式而危及伺服器的安全。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. 參數化的命令會藉此防衛從外部來源接收到的值會當做值,並不屬於 SQL 陳述式傳遞防衛 SQL 插入式攻擊。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. 如此一來,插入值的 SQL 命令不會執行在資料來源。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. 除了安全性優點,參數化的命令提供方便的方法,讓您安排以 SQL 陳述式或預存程序傳遞的值。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.

parameters 值可以是 DbParameter 物件的陣列或參數值的陣列。The parameters value can be an array of DbParameter objects or an array of parameter values. 如果只有提供值,則陣列DbParameter根據陣列中的值順序建立物件。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:

直接執行存放區命令Directly Executing Store Commands and

如何:直接針對資料來源執行命令How to: Directly Execute Commands Against the Data Source

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

直接針對資料來源執行查詢,並傳回具型別的結果序列。Executes a query directly against the data source and returns a sequence of typed results. 指定實體集和合併選項,以便能夠以實體形式追蹤查詢結果。Specify the entity set and the merge option so that query results can be tracked as entities.

public:
generic <typename TEntity>
 System::Data::Objects::ObjectResult<TEntity> ^ ExecuteStoreQuery(System::String ^ commandText, System::String ^ entitySetName, System::Data::Objects::MergeOption mergeOption, ... cli::array <System::Object ^> ^ parameters);
public System.Data.Objects.ObjectResult<TEntity> ExecuteStoreQuery<TEntity> (string commandText, string entitySetName, System.Data.Objects.MergeOption mergeOption, params object[] parameters);
member this.ExecuteStoreQuery : string * string * System.Data.Objects.MergeOption * obj[] -> System.Data.Objects.ObjectResult<'Entity>

類型參數

TEntity

傳回之資料的實體型別。The entity type of the returned data.

參數

commandText
String String String String

要使用資料來源的原生語言來執行之命令。The command to execute, in the native language of the data source.

entitySetName
String String String String

TEntity 型別的實體集。The entity set of the TEntity type. 如果未提供實體集名稱,則不會追蹤結果。If an entity set name is not provided, the results are not going to be tracked.

mergeOption
MergeOption MergeOption MergeOption MergeOption

要在執行查詢時使用的 MergeOptionThe MergeOption to use when executing the query. 預設為 AppendOnlyThe default is AppendOnly.

parameters
Object[]

要傳遞至命令的參數陣列。An array of parameters to pass to the command.

傳回

ObjectResult<TEntity>

型別為 TResult 之物件的列舉。An enumeration of objects of type TResult.

備註

ExecuteStoreQuery方法會使用現有的連接來執行任意命令直接針對資料來源。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.

呼叫 ExecuteStoreQuery 方法相當於呼叫 ExecuteReader 類別的 DbCommand 方法,只有 ExecuteStoreQuery 會傳回實體,而 ExecuteReader 會傳回 DbDataReader 中的屬性值。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.

指定實體集名稱,如果您想要當成實體追蹤的結果。Specify the entity set name, if you want for the results to be tracked as entities.

呼叫Translate方法來轉譯DbDataReader為實體物件時讀取器包含對應至指定的實體類型的資料列。Call Translate method to translate a DbDataReader into entity objects when the reader contains data rows that map to the specified entity type.

使用參數型命令 (Parameterized Command) 有助於防衛 SQL 插入式攻擊,在此類攻擊中,攻擊者會將命令「插入」至 SQL 陳述式而危及伺服器的安全。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. 參數化的命令會藉此防衛從外部來源接收到的值會當做值,並不屬於 SQL 陳述式傳遞防衛 SQL 插入式攻擊。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. 如此一來,插入值的 SQL 命令不會執行在資料來源。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. 除了安全性優點,參數化的命令提供方便的方法,讓您安排以 SQL 陳述式或預存程序傳遞的值。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.

parameters 值可以是 DbParameter 物件的陣列或參數值的陣列。The parameters value can be an array of DbParameter objects or an array of parameter values. 如果只有提供值,則陣列DbParameter根據陣列中的值順序建立物件。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:

直接執行存放區命令Directly Executing Store Commands and

如何:直接針對資料來源執行命令How to: Directly Execute Commands Against the Data Source

適用於