EF Model First with Stored Procedures

后端 未结 2 1678
别那么骄傲
别那么骄傲 2021-01-06 16:14

I\'m using EF 4 with model-first...I generate the database from the model. How would I be able to use stored-procedures in that scenario? They should also be auto-generated

2条回答
  •  心在旅途
    2021-01-06 16:52

    Ladislav is right except that I have found a probable workaround. I have tested this and it works although cannot tell if there are side effects to it.

    1. Download and install the Entity Designer Database Generation Power Pack (if you do not already have it of course).
    2. Update your database to the latest version of the model by doing the following (My apologies if you already know the following, this is for those that do not):
      A. Right click in the designer and select Generate Database From Model
      B. In the resultant Dialog box, select the Generate Migration SQL and Deploy option from the left hand side. (be sure to click the "Select Workflow ...." button at the top after you select this option).
      C. Click Next and you should see it do its stuff.
    3. Create your stored procedures in the database.
    4. Update your model from

    Now, your model and the database are synced. The trick is that in the future whenever you want to update either the database or the model first, just repeast steps 2, 3 and 4.

    You now have the best of both worlds! One word though is I would make sure you have the latest version of the power pack (you have to uninstall the old version from windows control panel then redownload the latest version and install it. If you do not update and you have VS2010 SP1 then the power pack will not display the necessary dialog box when you choose Generate Database and you would lose your stored procedures more than likely.

    Hope you like this. 3.

提交回复
热议问题