简体   繁体   English

LINQ to SQL包含存储过程和用户​​定义的表类型参数

[英]LINQ to SQL with stored procedures and user defined table type parameter

I am using LINQ to SQL with stored procedures in SQL Server 2008. Everything work well except one problem. 我在SQL Server 2008中使用LINQ to SQL和存储过程。除了一个问题,一切都很好。 L2S cannot generate the method for the stored procedure with user defined table type as parameter. L2S无法为用户定义的表类型作为参数生成存储过程的方法。 Method signature in dbml design panel use object for parameter type instead of table type and when I tried to compile I got error: 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数据访问。

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 Guard on 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: 更新2:
Unfortunately, according to Damien, this feature isn't supported in .NET 3.5, and will not be supported in .NET 4.0 either :-( 不幸的是,根据Damien的说法,.NET 3.5不支持此功能,.NET 4.0也不支持:-(

Can't be done in 3.5 or 4.0 right now 现在无法在3.5或4.0中完成
:( [)amien :( [] amien

I happened upon this post that provides a means of calling stored procedures with TVP parameters from Linq2Sql. 我发现这篇文章提供了一种从Linq2Sql调用TVP参数的存储过程的方法。 It's a round about method that basically creates a partial class extension of your dataContext and passes a dataTable using an SqlCommand. 它是一个round方法,基本上创建dataContext的部分类扩展,并使用SqlCommand传递dataTable。 I hope it helps. 我希望它有所帮助。

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 如何将表值参数从.net代码传递给存储过程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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