Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework - Call stored procedure with default parameters

I have some stored procedures mapped in Entity Framework using Database First. It creates strongly typed methods that you can call to run the stored procedures. I've run into a significant problem, however, in that I don't see any way to call these methods it created with the default parameters defined in the stored procedures. This means:

a) I have to manually add the default parameters to the method calls, which is brittle, if the default parameter value were to ever change.

b) Write method overloads by hand. This basically eliminates the benefit of generating a model from the database in the first place.

Does anyone know if there is a better solution to this problem?

Thanks.

like image 909
MgSam Avatar asked Jan 18 '13 14:01

MgSam


People also ask

Does Entity Framework allow calling stored procedure?

Entity Framework has the ability to automatically build native commands for the database based on your LINQ-to-Entities or Entity SQL queries, as well as build the commands for inserting, updating, and deleting data. You may want to override these steps and use your own predefined stored procedures.

How do you call a stored procedure in Entity Framework first?

Store node and then open the Stored Procedures node. Then right-click the GetCourses stored procedure and select Add Function Import. In the Add Function Import dialog box, under Returns a Collection Of select Entities, and then select Course as the entity type returned. When you're done, click OK.


1 Answers

As of Jan 2013, there's no supported way to do have the Entity Framework do this.

I have opened a feature request here.

like image 62
MgSam Avatar answered Sep 30 '22 20:09

MgSam