以下之间有什么区别-
CreateQuery() ExecuteFunction(), ExecuteStoreQuery() and ExecuteStoreCommand()
据我所知,CreateQuery 用于实体 SQL,其余方法用于数据库中定义的 sql 函数或存储过程。
根据 ObjectContext 类元数据,它们如下:
CreateQuery():Creates an System.Data.Objects.ObjectQuery<T> in the current object context by using the specified query string.
Returned -> System.Data.Objects.ObjectQuery<T>
ExecuteFunction(): 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.
Returned -> The number of rows affected.
This has an overloaded version which return -> The entity type of the System.Data.Objects.ObjectResult<T>
ExecuteStoreCommand(): Executes an arbitrary command directly against the data source using the existing connection.
Return -> The number of rows affected.
ExecuteStoreQuery(): Executes a query directly against the data source that returns a sequence of typed results.
Return -> An enumeration of objects of type TResult.
根据以上信息——
Use ExecuteFunction() if you have added db Function/Stored Procedure in your EDMX & can be used for both insert/update & getting result set.
Use ExecuteStoredCommand() if you have not added db Function/Stored Procedure in your EDMX & can be used to insert/update only.
ExecuteStoreQuery() can do what Executefuction() can do except that you no need to add your db Function/Stored Procedure in EDMX & IEnumerable can be used as return type.
如果我错了,请纠正我。任何进一步的信息将不胜感激。