I'm looking for the most elegant way of making Entity Framework call my stored procedures (delete, insert & update). The catch is that I use database-first, I can't change the stored procedures and there are more arguments to the stored procedures than there
are columns in the related table. Id rather not use functional imports since they have to be called by my code, and not by the framework. It doesn't feel elegant enough.
There is a nice solution for Linq to SQL. The code generator gives me Insert( instance) (and Delete, Update) partial methods that are called by the framework if I implement them in a partial class. From that method I just have to call this.() with the instance
variables and then add my extra arguments.
What is the easiest and most elegant way of doing this in Entity Framework?
This isn't something that I have had to do, but when you right-click a Entity in the EntityFramework .edmx file, there is an option for Stored Procedure Mapping that appears to let you pick the Insert/Update/Delete function.
And EntityFramework uses partial classes as well, so maybe it works somewhat similarly ?
Bjorn_E
Member
2 Points
5 Posts
Calling complicated stored procedures from Entity Framework?
Aug 24, 2012 08:50 AM|LINK
I'm looking for the most elegant way of making Entity Framework call my stored procedures (delete, insert & update). The catch is that I use database-first, I can't change the stored procedures and there are more arguments to the stored procedures than there are columns in the related table. Id rather not use functional imports since they have to be called by my code, and not by the framework. It doesn't feel elegant enough.
There is a nice solution for Linq to SQL. The code generator gives me Insert( instance) (and Delete, Update) partial methods that are called by the framework if I implement them in a partial class. From that method I just have to call this.() with the instance variables and then add my extra arguments.
What is the easiest and most elegant way of doing this in Entity Framework?
/BE
texx
Contributor
2412 Points
415 Posts
Re: Calling complicated stored procedures from Entity Framework?
Aug 24, 2012 03:02 PM|LINK
This isn't something that I have had to do, but when you right-click a Entity in the EntityFramework .edmx file, there is an option for Stored Procedure Mapping that appears to let you pick the Insert/Update/Delete function.
And EntityFramework uses partial classes as well, so maybe it works somewhat similarly ?
Bjorn_E
Member
2 Points
5 Posts
Re: Calling complicated stored procedures from Entity Framework?
Aug 24, 2012 04:01 PM|LINK
That does not work when you have more arguments to the SP than there are columns in the table.
I have done my homework...
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Calling complicated stored procedures from Entity Framework?
Aug 26, 2012 01:55 AM|LINK
I just come here to check whether your homework is done or not?
As far as I see, I think you have to use the traditional ADO,NET to deal with that, because some parameters cannot be mapped to the real Entity model.
Reguards!
Bjorn_E
Member
2 Points
5 Posts
Re: Calling complicated stored procedures from Entity Framework?
Nov 11, 2012 05:28 PM|LINK
I finally found out that this will come with EF 6, so I have decided to go with Function Imports for not.
/BE