I have a stored procedure that returns a table (or dataset or view or whatever it’s called, it returns the result of a select). I use entity framework and I’d expect it to treat the stored proc like a table by creating an entity. When I add the proc to the entity schema, it’s added but no class is generated (nothing appears on the schema or in the intellisense).
I do not want to use this dataset solution that looks ugly and unoptimised:
SqlCommand sqlCommand = new SqlCommand("sp_ProjetsVoxco");
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.Connection = new SqlConnection(
Settings.Default.ConnectionStringTransit);
SqlDataAdapter sa = new SqlDataAdapter(sqlCommand);
DataSet dataSet = new DataSet();
sa.Fill(dataSet);
I’ve found a line that seems to be very neat:
var x = context.ExecuteStoreQuery<T>("sp_ProjetsVoxco");
But since entity framework did not generate a class, I’m not really sure what to do with the T.
I’ll assume that you have your
edmxfile and you are now trying to add a Store Procedure that you already have created in the Database.1 – You should add your Store Procedure that by adding it just like any other table using the Update Model from database option, this will make EF to know about a SP. (Because I already have my SP I’m showing the
Refreshtab, but you will see your SP’s inAddtab if you didn’t add them yet)2 – Import a function
3 – Give it a name and create a new Complex Type
4 – Click OK and use the new method name