Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity framework 6.x doesn't add table valued parameter while adding in model

I'm trying to added stored procedure through Model browser, the SP had a table valued parameter. SP is added with function imports, But it's missing the table valued parameter. SP had 5 parameters including tvp, but i can see only 4 parameter and tvp parameter is missing.

I did googling to find the reason and solution. Everyone is suggesting to use entitie's ExecuteStoreProcedure method. e.g. Entity Framework Stored Procedure Table Value Parameter

But i want to use the function import which is created while we add SP using Model browser, all other SPs works well as they don't have tvp. Note: using EF 6.1.1 and .net 4.5, and VS2013

Quetion: does C# and EF supports importing SP wtih TVP ?

like image 576
Kireet Avatar asked Jan 27 '16 22:01

Kireet


People also ask

How do you call a table valued function in Entity Framework?

Step 1 − Select the Console Application from the middle pane and enter TableValuedFunctionDemo in the name field. Step 2 − In Server explorer right-click on your database. Step 3 − Select New Query and enter the following code in T-SQL editor to add a new table in your database.

What is a table valued parameter?

Table-valued parameters are declared by using user-defined table types. You can use table-valued parameters to send multiple rows of data to a Transact-SQL statement or a routine, such as a stored procedure or function, without creating a temporary table or many parameters.

When executing a command parameters must be exclusively database parameters or values?

When executing a command, parameters must be exclusively database parameters or values. Side note: you should not use the sp_ prefix for your stored procedures. Microsoft has reserved that prefix for its own use (see Naming Stored Procedures), and you do run the risk of a name clash sometime in the future.


1 Answers

A github post was submitted regarding the issue, concerning EF core but applicable to EF 6 as well:

  • Stored procedures are only supported in raw/inline SQL in Entity Framework Core.
  • Table Valued Parameters are only supported in raw/inline SQL in Entity Framework Core because we just pass any SqlParameter through
    to the underlying ADO.NET provider.
  • We initially used "Entity Framework 7" as the name for EF Core, but there is no released product called "Entity Framework 7" so I am not
    100% which product you are referring to.

Microsoft initial thought was to prepare EF 6 towards the new EF core standards, so they decided they will support the table valued parameters only on raw/inline sql.

You pass the SqlParameter to the underlying ado.net provider either way so there really is no reason to pass the param through Functions Import.

So yes, the way for you to go is to use ExecuteStoreProcedure as Microsoft is aptly prompting to do so, or just add the code yourself by extending the partial class with implementation of your own.

like image 76
Barr J Avatar answered Oct 07 '22 16:10

Barr J