locked
call stored procedure in code w/o return value RRS feed

  • Question

  • I am trying to call a stored procedure in code in entity framework.

    I'm not concerned about creating the procedure in code first anymore,

    like in my previous posts,

    because if I understand correctly, Visual Studio doesn't support that yet

    (I'm using 2010 so even if it's supported in 2012 I'm not going to do it that

    way if it's not supported in 2010, and from what I've read it's not supported).

    I've already created my stored procedure.

    The problem is the Database.SqlQuery class expects that the query returns

    something, it does not appear that the SqlQuery class supports no return

    queries.

    I do not know how to call a stored procedure in entity framework

    for a stored procedure that does not return a value.



    • Edited by jamesiw Friday, December 14, 2012 5:16 PM
    Friday, December 14, 2012 4:49 PM

Answers

  • If you just want to just run SQL use DbContext.Database.ExecuteSqlCommand.

    context.Database.ExecuteSqlCommand("EXEC myStoredProc");

     

    • Marked as answer by jamesiw Saturday, December 15, 2012 10:10 PM
    Saturday, December 15, 2012 1:45 AM

All replies

  • If you just want to just run SQL use DbContext.Database.ExecuteSqlCommand.

    context.Database.ExecuteSqlCommand("EXEC myStoredProc");

     

    • Marked as answer by jamesiw Saturday, December 15, 2012 10:10 PM
    Saturday, December 15, 2012 1:45 AM
  • Thanks a lot.
    Saturday, December 15, 2012 10:10 PM