none
Code First Migrations and SQL RRS feed

  • Question

  • Hi All, I would to know how to call a stored procedure from sql when also using migration classes. I'm really battling with this plz help...Thanks in advance.
    Saturday, July 19, 2014 3:03 PM

Answers

  • Hello,

    I do not quite understand what you are trying doing. Do you mean you want to call a stored procedure in the generated sql script by Package Manager Command? If you means it, then you run update-database command, you could add the –script flag. It would generate migration for changes in database script rather than apply changes to database directly:

    Update-Database –Script

    With the generated sql script, you could add whatever sql you want include calling the stored procedure.

    If I misunderstand, please let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, July 21, 2014 5:41 AM
    Moderator

All replies

  • Hello,

    I do not quite understand what you are trying doing. Do you mean you want to call a stored procedure in the generated sql script by Package Manager Command? If you means it, then you run update-database command, you could add the –script flag. It would generate migration for changes in database script rather than apply changes to database directly:

    Update-Database –Script

    With the generated sql script, you could add whatever sql you want include calling the stored procedure.

    If I misunderstand, please let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, July 21, 2014 5:41 AM
    Moderator
  • Thanks Fred what I actually mean is, the procedure is there but i don't know what code to use when calling the stored procedure from the database to the business logic class.
    Monday, July 28, 2014 5:15 PM
  • Hello,

    >> what I actually mean is, the procedure is there but i don't know what code to use when calling the stored procedure from the database to the business logic class.

    Since you already have a database, you are working with database first approach, then you need to import the stored procedure to the model from database, and with the instance of your dbcontext, you can call the stored procedure directly since it would be a method of your dbcontext class, you can follow this link:

    http://www.entityframeworktutorial.net/stored-procedure-in-entity-framework.aspx

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, July 29, 2014 6:40 AM
    Moderator