none
Entity Framework v5 or v6 unmapped properties RRS feed

  • Question

  • When using EF v5 or v6 is it possible to have an entity with a property that is not in the database but is required for the stored procedure insert procedure?  For example, I have a DB Table Customer(custID,custName,custPhone). The EF data class Customer with properties for custID, custName, custPhone, and also the stored procedure spCustInsert(custID,custName,custPhone). This works fine as is. Now say the requirement changes to generate the new CustID based off some other data, a siteID or similar. The siteID won't be in DB table. So now if stored procedure spCustInsert(custID,custName,custPhone,siteID) is used for insert operation on Customer entity, how can Customer entity know to include the siteID value when creates the call to spCustInsert? 

    The problem seems to be that I cannot use an unmapped column as an argument to the insert stored procedure. Is there a solution to this or does everyone just have to make stored procedures that map 1 to 1 with the database mapped entity properties?

    Monday, March 3, 2014 9:57 PM

Answers

  • Hello,

    >> Is there a solution to this or does everyone just have to make stored procedures that map 1 to 1 with the database mapped entity properties?

    For this issue, if you are using store procedure to insert, update and delete operations which is mapped to entity in the Store Procedure Mapping like here, there is a discussion which is similar:

    http://social.msdn.microsoft.com/Forums/en-US/c63475a5-9da1-4bfd-8c89-a8acad2642b3/stored-procedures-without-a-complete-mapping-to-ef-tables?forum=ado

    You can do that, however, you will lose the ability to query the table since the SSDL is not mapped the table in database, this is not recommended. Code First in Entity Framework 6 also needs one to one mapping.

    If we call the store procedure directly, yes, we can do since we do not need to make sure one to one mapping between parameters and fields.

    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.

    • Marked as answer by Babble0n Tuesday, March 4, 2014 7:14 PM
    Tuesday, March 4, 2014 2:19 AM
    Moderator

All replies

  • Hello,

    >> Is there a solution to this or does everyone just have to make stored procedures that map 1 to 1 with the database mapped entity properties?

    For this issue, if you are using store procedure to insert, update and delete operations which is mapped to entity in the Store Procedure Mapping like here, there is a discussion which is similar:

    http://social.msdn.microsoft.com/Forums/en-US/c63475a5-9da1-4bfd-8c89-a8acad2642b3/stored-procedures-without-a-complete-mapping-to-ef-tables?forum=ado

    You can do that, however, you will lose the ability to query the table since the SSDL is not mapped the table in database, this is not recommended. Code First in Entity Framework 6 also needs one to one mapping.

    If we call the store procedure directly, yes, we can do since we do not need to make sure one to one mapping between parameters and fields.

    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.

    • Marked as answer by Babble0n Tuesday, March 4, 2014 7:14 PM
    Tuesday, March 4, 2014 2:19 AM
    Moderator
  • Thank you so much for the reply Mr. Bao. The desired end result of this exercise is to be able to continue using the entity framework's SaveChanges() method and avoid calling individual stored procedures for updates, deletes and inserts directly. So as I understand it, it is not possible using EF in any combination of version and design/code first approach to have anything other than a strict 1 to 1 mapping between entity properties and insert/update stored procedure parameters for that entity. That is, any parameter in the related update/insert stored procedure MUST be in the list of entity properties, even if using code first rather than design first.  

    Is that a correct statement? I am sorry for the seemingly obtuse and repeated rephrasing of this question. I just really need to make sure that this is indeed the case, and that no workaround, or no recommended work around exists. 

     Thank you very much.
    Tuesday, March 4, 2014 3:47 AM
  • >>Is that a correct statement?

    Yes, you are right.  And if you want the Entity Framework has such a feature, you can post your wish to:

    http://data.uservoice.com/forums/72025-entity-framework-feature-suggestions and vote it.


    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, March 4, 2014 7:35 AM
    Moderator