فکر کنم فرق اصلی در بازگشتی و بدون بازگشت بودن اونهاست یعنی در query شما باید نوع برگشتی رو مشخص کنید ولی در command خیر
context.ExecuteStoreCommand
This command can be used to execute SQL/PSQL commands that don't return any values for e.g. insert/delete statements.
1: using (var context = new EFRecipesEntities()) 2: { 3: context.ExecuteStoreCommand("delete from chapter10.Product"); 4: context.ExecuteStoreCommand("insert into chapter10.Product values ('Chai', 'Beverage')"); 5: }
context.ExecuteStoreQuery<TElement>
If you need to execute a SQL/PSQL that returns record sets then use context.ExecuteStoreQuery<TElement> where TElement can be an existing Entity in the CSDL of the EDMX file, or if the result does not map to an existing Entity in the CSDL then use context.ExecuteStoreQuery<DbDataRecord> to iterate over the columns of the returned results manually using indexers on DbDataRecord to access column values. Note that context.ExecuteStoreQuery<> returns a ObjectResult<TElement> which be iterated over only once as opposed to ObjectSet<T> or ObjectQuery<T> which can be iterated over multiple times.
1: using (var context = new EFRecipesEntities()) 2: { 3: string sql = "select * from Chapter3.Student where Degree = @Major"; 4: var args = new DbParameter[] { new SqlParameter { ParameterName = "Major", Value = "Masters" } }; 5: var students = context.ExecuteStoreQuery<Student>(sql, args); 6: }