I use the MySQL base. The database has a stored procedure, in which there are several select queries, for unloading certain chunks of data. Can you please tell me how to use the Entity Framework to access the stored procedure and pass parameters?
- how to use the Entity Framework to access the stored procedure From this side there is no difference between the HP, the view and the request. and pass the parameters And here too. - Akina
- @Akina, can I give you the simplest example of code? - dexploizer
- For examples - to those who work on the EF side. - Akina
|
1 answer
Like that
using(var db = new DbContext()) { var param = new System.Data.SqlClient.SqlParameter("@your_param_name", "your_value"); var data= db.Database.SqlQuery<YourEntityName>("YourStoredProcedureName @your_param_name", param); foreach (var d in data) { // Do something with your data } } - Many thanks for the example! But, unfortunately, I do not get the desired result, although a call to the database with the same parameter displays the necessary information - dexploizer
YourEntityNameobviously needs to be replaced with a suitable entity. Not the fact that you have one. What does a procedure return, arbitrary data set or typed? - AnatolYourEntityName очевидно нужно заменить подходящей сущностью- this is understandable. If I call another procedure (without parameters), everything is normally displayed - dexploizer- I repeat the question - what does the first procedure return? simple and visual solution - to create an entity that copies the result returned by the procedure - Anatol
- oneEverything, found the error. Thank you for your help - dexploizer February
|