I have been messing with this all morning, but I can't find the answer. I am trying to use EF to reference a stored procedures, but no matter what I try I cannot get it to show up in the model browser.
I have used the following steps to try to get the procedures into the modal:
add procedure to Entity model
right click on model and choose add new --> Function Import
Give it a name and select my procedure
generate a new complex collection (I have also tried using an entity, neither work)
click OK
I have done this many times, and I can see the function in the "function Imports" folder in the model, but it never shows up in the model, so I can't reference it.
I find I can reference the stored procedure directly (without the import) by doing the following:
DBEntities db = new DBEntities();
var test = db.gsp_GetGroups();
However, I cannot convert this to IQueryable<T>
without a big workaround.
Does anybody know what steps I'm missing to get this to add properly?
Thanks
P.S. VS 2012, asp.net 4.0
You can use stored procedures either to get the data or to add/update/delete the records for one or multiple database tables. EF API creates a function instead of an entity in EDM for each stored procedure and User-Defined Function (UDF) in the target database.
The quick and simple way to monitor the stored procedures execution is setting up a Trace with SQL Server Profiler. This is probably good for a quick check when a user runs a process in Test and you want to capture what is he/she running.
EF Core already supports querying data from stored procedures. This feature will allow mapping the inserts, updates, and deletes generated by SaveChanges to stored procedures in the database.
Verify that the SQL log-in you are using to generate your EF model has permission to execute the stored procs you are trying to import.
connectionStrings
entry (usually at the bottom). If you have more than 1 connection string, the one you want is the one your context uses.
MyDbModel.edmx
, then under that you'll have MyDbModel.Context.tt
which in turn will contain MyDbModel.Context.cs
.MyDbModel.Context.cs
file you will have a class that inherits from DbContext
and the constructor will call base("name=<your connection string name>")
<your connection string name>
is the one you are looking for in your app.config.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With