简体   繁体   中英

How to pass a list of data to a stored procedure, using Entity Framework 6

I am trying to pass a list of data from C# to a SQL Server stored procedure, using Entity Framework Database First. There are lots of articles in SO and elsewhere about the problem, but it is not obvious which refer to passing variable data to the stored procedure and those returning variable data from the database. They also tend to focus on the code to call the stored procedure but I cannot get that far.

A user-defined table type and a stored procedure were created and tested in SSMS. The problem occurred in the C#. When updating the model (.edmx file), this warning is issued:

Warning 4 Error 6005: The function 'uspGetBusyPersonsTVP' has a parameter 'list' at parameter index 2 that has a data type 'table type' which is currently not supported for the target Entity Framework version. The function was excluded.

Examination in the Model Browser shows that the stored procedure has been created in the model, but only with the non-TVP parameters.

This MSDN site https://msdn.microsoft.com/en-us/data/hh859577.aspx says that table-valued parameters have been supported since EF 5.0, but the article only talks about returning data.

I have just finished updating and I am now using Visual Studio 2015 Community, .Net 4.6 and Entity Framework 6.1.3. Does anyone know if a TVP can be passed to a stored procedure, or if it is ever likely to be supported?

The article you reference talks about table-valued functions (ie a user-defined function that returns a table), not about passing table-value parameters to a stored procedure. You're comparing apples and elephants.

Whether EF will ever support it I can't answer as I don't work for Microsoft. Whether it can be done, the answer appears to be "yes" based on How to pass table value parameters to stored procedure from .net code , however it appears you'll need to use raw ADO.NET to do it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM