存储过程和实体框架 4.0 中的表值参数

2023-10-26数据库问题
0

本文介绍了存储过程和实体框架 4.0 中的表值参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在 SQL Server 2008 中有一个名为GetPrices"的存储过程,带有一个名为StoreIDs"的表值参数.

I have a stored procedure in SQL Server 2008 called 'GetPrices' with a Table-Valued Parameter called 'StoreIDs'.

这是我为此 TVP 创建的类型:

This is the type i created for this TVP:

CREATE TYPE integer_list_tbltype AS TABLE (n int)

我想从我的实体框架调用 SP.但是当我尝试将存储过程添加到 EDM 时,出现以下错误:

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:

函数GetPrices"在参数索引 2 处有一个参数StoreIDs",该参数具有不受支持的数据类型表类型".该函数已被排除.

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?

法比奥

推荐答案

我同意在这种情况下传递 CSV 刺是最好的解决方案.我想提出一种更简单的方法来拆分 csv 字符串,而无需使用 CTE 创建表和函数:

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:

declare @separator char(1);
set @separator = ',';

;with baseCte as
(select left(@ValueList, charindex(@separator, @ValueList) - 1) as Value,
substring(@ValueList, charindex(@separator, @ValueList) + 1, len(@ValueList)) 
as rest
union all
select left(rest, charindex(@separator, rest) - 1) as Value, 
substring(rest, charindex(@separator, rest) + 1, len(rest)) from baseCte
where len(rest) > 1
)
select Value from baseCte
OPTION (MAXRECURSION 0);

这篇关于存储过程和实体框架 4.0 中的表值参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

按天分组的 SQL 查询
SQL query to group by day(按天分组的 SQL 查询)...
2024-04-16 数据库问题
77

在 Group By 查询中包含缺失的月份
Include missing months in Group By query(在 Group By 查询中包含缺失的月份)...
2024-04-16 数据库问题
12

sql group by 与不同
sql group by versus distinct(sql group by 与不同)...
2024-04-16 数据库问题
37

如何在SQL中返回每个组的增量组号
How to return a incremental group number per group in SQL(如何在SQL中返回每个组的增量组号)...
2024-04-16 数据库问题
8

统计分组返回的记录数
Count number of records returned by group by(统计分组返回的记录数)...
2024-04-16 数据库问题
10

带聚合函数的 SQL GROUP BY CASE 语句
SQL GROUP BY CASE statement with aggregate function(带聚合函数的 SQL GROUP BY CASE 语句)...
2024-04-16 数据库问题
23