2
        DbContext.Database.ExecuteSqlCommand(sql, parameters)

I am using above method of Entity Framework to execute SP which takes table valued parameter and perform some operation.

It is successfully doing its task and I can see the result in the database. But it always return -1, no matter the query is successfully executed or not. I think, it should return 1 if the query execution is successful.

Could someone clarify me. Thanks

Nabin
  • 163
  • 1
  • 12
  • The return value of a stored-procedure is defined in the procedure itself. Please post the source code of the procedure. – Dai Mar 15 '16 at 23:00
  • Without seeing the stored procedure, we can't be sure why it is returning -1. – Ellesedil Mar 15 '16 at 23:00
  • 1
    `ExecuteSqlCommand` returns the result returned by the database after executing the command. That is, if you expect a result you must return it from your sp. What are you returning from the store procedure? – Balde Mar 15 '16 at 23:05
  • 1
    store procedure does only select and insert operation, it does not return anything. I am thinking that, once the execution of sp is done successfully then ExecuteSqlCommand() will return 1 and if there is any issue while execution then it returns -1. – Nabin Mar 15 '16 at 23:07

1 Answers1

-1

EF does not support Table Valued Parameters. This SO thread points however to an extension you could potentially use to achieve what you want. (Note I have not tried the extension so don't know whether it works well).

Community
  • 1
  • 1
Pawel
  • 31,342
  • 4
  • 73
  • 104
  • I am able to send table valued parameter in the sp by specifying SqlParameter parameter = new SqlParameter(paramName, table); parameter.SqlDbType = SqlDbType.Structured; parameter.TypeName = typeName; and the sp is executed and I am able to see the correct result in the database. But I was assuming that ExecuteSqlCommand() returns 1 or -1 based success or failure of query execution. – Nabin Mar 16 '16 at 00:37