locked
why doesn't edmx autogenerate objects for stored procs? RRS feed

  • Question

  • User1610691276 posted

    Why doesn't edmx autogenerate objects for stored procs in EF4.0?  Linq-to-SQL does this.  I know I can go to the edmx designer and add stored procs manually one at a time. However, I like to delete and recreate my edmx whenever I make a few datamodel changes.  It's just a lot easier to just drop and recreate the edmx all at once.

    If I have 20 stored procedures I don't want to have to add them all back one at a time - that shouldn't be necessary.  So is there a service pack, patch or add in for VS2010 that will include stored procs in the edmx generation now?  My current system setup doesn't appear to handle this.

    Also - it seems weird that the edmx generator allows you to select stored procs for auto-generation through the model generation wizard but the proc stubs don't seem to get generated.  Am I missing something?

     

    Friday, February 10, 2012 6:57 PM

Answers

  • User3866881 posted

    Dong - yes - what you're saying works but I'd like the ability to add all sp's at once in batch. Linq to SQL includes all the sp's in the model by default. EF lets you select "include sp's" option in the gen wizard. But EF doesn't actually include them in batch as expected....

    No,I think it has the function——

    Just create an edmx file and it will pop up a wizard,in the wizard,after you select a database to create,notice that it has included a Stored Procdure——Then you can select as many as Stored procdure as you would like……Here's the screenshot about that。

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 11, 2012 11:05 PM
  • User3866881 posted

    Hello again:)

    You mean you don't know how to find the auto-generated method from the stored procdure?Please use something like this:

     using (var db = new XXXEntities())

                {

                    var result = db.XXXX;  //Stored procdure

                }

    If you still cannot find that,plz double click the edmx file and right click a certain object model class,and then choose "Function Import",then import the stored procdure you want and recompile your whole proj……It should work。

    Reguards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 14, 2012 2:34 AM

All replies

  • User3866881 posted

    If I have 20 stored procedures I don't want to have to add them all back one at a time - that shouldn't be necessary.  So is there a service pack, patch or add in for VS2010 that will include stored procs in the edmx generation now?  My current system setup doesn't appear to handle this.

    Until now,as far as I see……,I don't think there's such a thing of package or VS-addin……;maybe you can try to right click the model and choose "Function Import"…… to have a try with。

    Saturday, February 11, 2012 9:40 PM
  • User1610691276 posted
    Dong - yes - what you're saying works but I'd like the ability to add all sp's at once in batch. Linq to SQL includes all the sp's in the model by default. EF lets you select "include sp's" option in the gen wizard. But EF doesn't actually include them in batch as expected....
    Saturday, February 11, 2012 9:48 PM
  • User3866881 posted

    Dong - yes - what you're saying works but I'd like the ability to add all sp's at once in batch. Linq to SQL includes all the sp's in the model by default. EF lets you select "include sp's" option in the gen wizard. But EF doesn't actually include them in batch as expected....

    No,I think it has the function——

    Just create an edmx file and it will pop up a wizard,in the wizard,after you select a database to create,notice that it has included a Stored Procdure——Then you can select as many as Stored procdure as you would like……Here's the screenshot about that。

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 11, 2012 11:05 PM
  • User1492915735 posted

    Hi,

    Just right click then update from Database. If so as you said you'd better study some .EDMX's language.

    http://msdn.microsoft.com/en-us/library/cc982040.aspx

    Sunday, February 12, 2012 12:15 AM
  • User1610691276 posted

    Dong - Yes I'm selecting the "Stored Procedures" option when I generate the model but the stored procedures don't get added to the model.  I think this may be a gap in EF functionality.  I can add the sp's manually as the poster below you described but I want to do this in batch (all at once) instead of one at a time for obvious reasons.

    Dong - I can see that you're familiar with EF based on your wizard screenshot.  After you complete the wizard to create your model can you try to create a context variable and access your "GetAllUsers" sp through your EF context?  If that option is not available then you should understand my problem.  If that option *is* available then something is missing on my end - maybe a VS service pack or maybe permissions settings on the sp's.

    So will you please try to access your "GetAllUsers" sp through your EF context after using the wizard and let me know if you're able to access your sp through your context?

     

     

    Monday, February 13, 2012 10:35 AM
  • User3866881 posted

    My steps are:

    1)Please first confirm that the Stored Procdure is inside the database。

    2)Please delete your edmx file and then right click your proj to create a new edmx file,in the wizard,you should see the dialog as my screenshot,and the Stored Procdure is just there。

    Regaurds!

    Monday, February 13, 2012 8:19 PM
  • User1610691276 posted
    Yes Dong - "Stored Procedures" is an option for selection in the edmx wizard. And each sp in the db is displayed for selection in the wizard. However, if you click through the wizard and click Finish the stored procs aren't actually there for selection through dot notation when you try to access them by creating an instance of the model. Please let me know if you have a different result....
    Monday, February 13, 2012 8:25 PM
  • User3866881 posted

    Hello again:)

    You mean you don't know how to find the auto-generated method from the stored procdure?Please use something like this:

     using (var db = new XXXEntities())

                {

                    var result = db.XXXX;  //Stored procdure

                }

    If you still cannot find that,plz double click the edmx file and right click a certain object model class,and then choose "Function Import",then import the stored procdure you want and recompile your whole proj……It should work。

    Reguards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 14, 2012 2:34 AM