Solved

Mapping CRUD SPs to Entity Framework table objects

Posted on 2014-02-26
2
1,035 Views
Last Modified: 2014-03-13
I am using CRUD stored procedures toa carry out changes to my data.  I see how you are supposed to map the parameters to the EF table's fields.  My question comes because I have an extra field in the Stored Procedure that does not map to the table reflecting the userRecID of the person making the change.  (That is because this has to be stored in a tracking table in the database.)

However, when I tried to set the mapping I would get errors because there was not a one to one correspondence between the parameters and the columns.  

In this MSDN article ¿http://msdn.microsoft.com/en-us/data/gg699321.aspx in the section entitled "Mapping Modification Stored Procedures to Entities"

it states:

Now you’ll modify the model so that the Entity Framework will use the UpdateOrder stored procedure defined in the database instead of generating its own command. You’ll do this by mapping the UpdateOrder stored procedure to the Order entity in the designer. This is referred to as Stored Procedure Mapping or Function Mapping.

1.In the designer, right click on the Order entity and select Stored Procedure mapping.
2.Click select Function="" Insert="" and then click the drop down arrow that appears. This exposes the list of all Functions found in the Store metadata.
3.Select InsertOrder from the list. The designer will do its best job of matching the stored procedure’s parameters with the entity properties using the names. In this case, since all of the property names match the parameter names, it maps every one correctly so you don’t need to make any changes. One thing that the designer was not able to map is the newly generated SalesOrderID returned by the stored procedure. This is because the designer is not able to automatically detect the name of the field being returned.
4.Under the Result Column Bindings section, click add Binding="" Result="" and enter SalesOrderID. The designer should automatically select the entity key property, OrderID, for this final mapping.
When completed, Figure 6 displays what the mapping should look like.

However when I follow this process because my stored procedure contains an extra parameter I get the error, "Error 2037: A mapping function bindings specifies a function VFS_ProcurementTrackModel.Store.prc_ext_Requirement_Insert but does not map the following function parameters: UserRecID."

This has me stymied in attempting to "map" the prc_ext_Requirement_Insert stored procedure to the prc_Requirements Entity.

How do I get around this?
0
Comment
Question by:Edward Joell
  • 2
2 Comments
 

Accepted Solution

by:
Edward Joell earned 0 total points
ID: 39926896
After extensive discussion on www.Asp.Net it was developed that the answer is "you can't get there from here".

So I will instead have to import my stored procedures as functions and call them to carry out my update activities.  I have to build my own custom objects to implement these crud calls.  I will only be able to use EF only as a means of build models of my tables and nothing else.  I would be able to use any of the EF objects' savechanges methods or if changed properties.
0
 

Author Closing Comment

by:Edward Joell
ID: 39926899
Essentially I am making the best of a bad deal.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now