I have a stored procedure in SQL Server 2008 called 'GetPrices' with a Table-Valued Parameter called 'StoreIDs'.
This is the type i created for this TVP:
CREATE TYPE integer_list_tbltype AS TABLE (n int)
I would like to call the SP from my Entity Framework. But when I try to add the Stored Procedure to the EDM, i get the following error:
The function 'GetPrices' has a parameter 'StoreIDs' at parameter index 2 that has a data type 'table type' which is not supported. The function was excluded.
Is there any workaround this? Any thoughts?
Fabio
I agree that passing in a CSV sting is the best solution in this case. I would like to propose simpler way to split csv string, without creating tables and functions, by using CTE:
You can use the ObjectContext.Connection property to use ADO.NET to create and use your table-valued parameters. This might not be acceptable, but if you want to use this awesome SQL Server 2008 feature and the EF, this seems to be you're only choise.
You can then choose to extent the partially generated object context with the method to take care of all the low level ADO.NET stuff. Like this:
Since you can't use a table parameter, try passing in a CSV sting and have the stored procedure split it into rows for you.
There are many ways to split string in SQL Server. This article covers the PROs and CONs of just about every method:
"Arrays and Lists in SQL Server 2005 and Beyond, When Table Value Parameters Do Not Cut it" by Erland Sommarskog
You need to create a split function. This is how a split function can be used:
I prefer the number table approach to split a string in TSQL but there are numerous ways to split strings in SQL Server, see the previous link, which explains the PROs and CONs of each.
For the Numbers Table method to work, you need to do this one time table setup, which will create a table
Numbers
that contains rows from 1 to 10,000:Once the Numbers table is set up, create this split function:
You can now easily split a CSV string into a table and join on it or use it however you need:
You might want to vote on this at microsoft connect
Update: MS does not use Connect for features any more. They only use it for bug reports. To vote for an EF feature you need to go the EF User Voice site.
To vote for this specific issue on User Voice go here.