MySQL Forums :: MySQL for Visual Studio :: How to call MySql stored procedure with input, output parameters in entity framework database first approach


Advanced Search

Re: How to call MySql stored procedure with input, output parameters in entity framework database first approach
Posted by: Luis Penunuri ()
Date: January 18, 2016 01:06PM

Hi Nandkishor,

Thank you for use MySQL as your DB Provider.

The methodology to execute a Stored Procedure with Entity Framework using MySQL is pretty much the same as the one for SQL Server:

1.- Create the model (edmx)
2.- Select the stored procedures you want to include in the model
3.- Create a Function Import for each stored procedure you imported to the model, selecting the proper function return type. This way, the stored procedure will be available through the DB context.
4.- Execute the stored procedure through the context.
i.e.:
sakilaEntities ctx = new sakilaEntities();
ObjectParameter filmCount = new ObjectParameter("p_film_count", typeof(Int32));
var films = ctx.film_in_stock(1, 1, filmCount);

In the example above, I'm calling the Sakila's DB stored procedure "film_in_stock", which has two input parameters and one output parameter.
(Note: I used VS2010, MVC 4, MySQL Server 5.6, MySQL Connector/Net 6.3.9 and MySQL for Visual Studio 1.2.6 to execute the example above).

You can take a look to the ADO.NET Entity Framework official documentation (https://msdn.microsoft.com/library/bb896334%28v=vs.100%29.aspx?f=255&MSPPError=-2147217396), as well at the following Entity Framework tutorial (http://www.entityframeworktutorial.net/EntityFramework4.3/execute-stored-procedure-using-dbcontext.aspx) for further information.


Thanks, and have a good one !

Options: ReplyQuote


Subject Views Written By Posted
How to call MySql stored procedure with input, output parameters in entity framework database first approach 1405 Nandkishor K 12/18/2015 03:48AM
Re: How to call MySql stored procedure with input, output parameters in entity framework database first approach 914 Luis Penunuri 01/18/2016 01:06PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.