C# 带有存储过程和用户定义表类型参数的 LINQ to SQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1019414/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
LINQ to SQL with stored procedures and user defined table type parameter
提问by Dmitri Kouminov
I am using LINQ to SQL with stored procedures in SQL Server 2008. Everything work well except one problem. L2S cannot generate the method for the stored procedure with user defined table type as parameter. Method signature in dbml design panel use object for parameter type instead of table type and when I tried to compile I got error:
我在 SQL Server 2008 中使用带有存储过程的 LINQ to SQL。除了一个问题外,一切都运行良好。L2S 无法为以用户定义的表类型作为参数的存储过程生成方法。dbml 设计面板中的方法签名使用对象作为参数类型而不是表类型,当我尝试编译时出现错误:
Error: DBML1005: Mapping between DbType 'Structured' and
Type 'System.Object' in Parameter 'ParaName' of Function 'dbo.StoredProcName'
is not supported.
Is there a way to work around this of this problem? I don't want to go back to traditional ADO.NET data access.
有没有办法解决这个问题?我不想回到传统的 ADO.NET 数据访问。
采纳答案by marc_s
I don't think there's anything available right now - table-valued parameters were introduced in SQL Server 2008 - after LINQ and LINQ2SQL were out already.
我认为现在没有任何可用的东西——表值参数是在 SQL Server 2008 中引入的——在 LINQ 和 LINQ2SQL 已经推出之后。
I haven't found any mention in any of the blog post about support for table-valued parameters in LINQ2SQL in .NET 4.0 so far.
到目前为止,我在任何博客文章中都没有发现任何关于 .NET 4.0 中 LINQ2SQL 中表值参数支持的提及。
UPDATE:
Here's a blog post by Damien Guardon the fixes and improvement for Linq-to-SQL in the .NET 4.0 time frame.
更新:
这是Damien Guard关于 .NET 4.0 时间范围内 Linq-to-SQL 的修复和改进的博客文章。
UPDATE 2:
Unfortunately, according to Damien, this feature isn't supported in .NET 3.5, and will not be supported in .NET 4.0 either :-(
更新 2:
不幸的是,根据 Damien 的说法,.NET 3.5 不支持此功能,.NET 4.0 也不支持此功能:-(
Can't be done in 3.5 or 4.0 right now
:( [)amien
现在不能在 3.5 或 4.0 中完成
:( [)amien
回答by cboler
I happened upon this postthat provides a means of calling stored procedures with TVP parameters from Linq2Sql. It's a round about method that basically creates a partial class extension of your dataContext and passes a dataTable using an SqlCommand. I hope it helps.
我偶然发现了这篇文章,它提供了一种从 Linq2Sql 调用带有 TVP 参数的存储过程的方法。这是一个循环方法,它基本上创建了 dataContext 的部分类扩展,并使用 SqlCommand 传递了一个 dataTable。我希望它有帮助。
回答by VicariousAT
I had the exact same problem and Ryan Prechel's sample code from the following link helped me solve the problem.
我遇到了完全相同的问题,来自以下链接的 Ryan Prechel 的示例代码帮助我解决了这个问题。
How to pass table value parameters to stored procedure from .net code