Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's not because of the parameter order in your parameters object - it's because in your second code snippet you're explicitly passing the <code>@Code</code> value as the first parameter when the SP is expecting a <code>Member INT</code> value. </p> <pre><code>var result = context.Database.SqlQuery&lt;resultClass&gt;("mySpName @Code, @member,@PageSize,@PageNumber" parameters).ToList(); </code></pre> <p>...you're passing in <code>"0165210662660001"</code> as the first parameter and the conversion to INT is failing.</p> <p>The order of your parameters in your parameters object is irrelevant as EF (ADO.NET actually) will map those parameters to the <code>@parametername</code> values in your query string. So the <code>new SqlParameter("Code","0165210662660001")</code> will be mapped into the <code>@Code</code> position in your query - which int the second code snipped is actually the position for the Member value as expected by the SP. </p> <p>However... you can execute a SP using named parameters as well and in that case you can pass the parameters to the SP in any order as below:</p> <pre><code>db.Database.SqlQuery&lt;resultClass&gt;("mySpName PageNumber=@PageNumber,Code=@Code,PageSize=@PageSize,Member=@member", parameters).ToList(); </code></pre> <p>You see that I'm not passing the params to the SP in the order they were defined [by the SP] but because they're named I don't have to care.</p> <p>For different ways of passing params see: This <a href="https://stackoverflow.com/questions/4873607/how-to-use-dbcontext-database-sqlquerytelementsql-params-with-stored-proced">Answer</a> for some good examples.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload