title: Entity Framework - CreateQuery VS ExecuteFunction VS ExecuteStoreQuery VS ExecuteStoreCommand
body: <p>What are the differences between following-</p>
  
  <pre><code>CreateQuery()  ExecuteFunction(), ExecuteStoreQuery() and ExecuteStoreCommand() 
  </code></pre>
  
  <p>As per my knowledge CreateQuery is used for Entity SQL &amp; rest of the methods are used for sql function or stored procedure defined in DB.</p>
  
  <p>As per ObjectContext class meta data they are as follow:</p>
  
  <pre><code>CreateQuery():Creates an System.Data.Objects.ObjectQuery&lt;T&gt; in the current object context        by using the specified query string. 
  Returned -&gt; System.Data.Objects.ObjectQuery&lt;T&gt;
  
  
  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 -&gt; The number of rows affected.
  This has an overloaded version which return -&gt; The entity type of the System.Data.Objects.ObjectResult&lt;T&gt; 
  
  
  ExecuteStoreCommand(): Executes an arbitrary command directly against the data source using the existing connection.
  Return -&gt; The number of rows affected.
  
  
  ExecuteStoreQuery(): Executes a query directly against the data source that returns a sequence of typed results.
  Return -&gt; An enumeration of objects of type TResult.
  </code></pre>
  
  <p>As per above information -</p>
  
  <pre><code>Use ExecuteFunction() if you have added db Function/Stored Procedure in your EDMX &amp; can be used for both insert/update &amp; getting result set.
  
  Use ExecuteStoredCommand() if you have not added db Function/Stored Procedure in your EDMX &amp; 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 &amp; IEnumerable can be used as return type.
  </code></pre>
  
  <p>Please correct me if I am wrong. Any further information will be highly appreciated.</p>