locked
Stored Procedure Mapping RRS feed

  • Question

  • Hi all,

    In my stored procedure, I check if the parameter (primary key field) is zero or not. If its zero then the new value is generated and assigned to that parameter and then inserted into the table (Suppose the user enter some value that value is directly inserted into the table otherwise generated inside the procedure). After inserting one identity value and this parameter value is returned to the entity model. I map all the fields to the entity. Actual problem here is the resultset mapping. It gave the error while inserting but when I remove the resultset  mapping for the key field then everything works fine. 

    How do I solve this issue? Basically I can't map both parameter and result column binding for same field.

    Thanks in advance


    Regards, Arun
    Tuesday, July 6, 2010 11:31 AM

Answers

All replies

  • Hi Arun,

     

    Glad to see you again!

     

    I can repro the problem based on your description.  Do you receive the same exception as the one in this thread, http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/5acc95f2-2442-47cf-b407-bc9a667a6a35?    If the primary key column is mapped on both the parameter and resultset, we receive the exception. 

     

    I think it’s a limitation of the current EF.   Can you move the auto-generation key logic to the client side?   We can handling SavingChanges() event and check if the key is zero then we auto-generate a new key for it, then we don’t need to map the resultset.  

     

    Good day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Arunkumar.B Wednesday, July 7, 2010 5:23 AM
    Wednesday, July 7, 2010 3:22 AM
  • I doubt if you can do this in EF. However can u make sure StoreGeneratedPattern=identity on the SSDL layer for this property. I wonder if you use this attribute, will EF take any value that you pass in from the client because this essentially means the value is generated at the storage layer so it might ignore any value you set on the client side.
    Zeeshan Hirani Entity Framework 4.0 Recipes by Apress
    http://weblogs.asp.net/zeeshanhirani
    Wednesday, July 7, 2010 5:12 AM