在 SQL Server 存储过程中使用 LINQ to SQL 结果
注意:我没有尝试使用L2SQL数据上下文调用SQL Server存储过程。
我使用 LINQPad 进行一些相当复杂的“报告”,将 L2SQL 输出保存到数组中并进行进一步处理。
例如,使用 LINQ to Objects 进行多个级别的分组通常比尝试优化 T-SQL 查询以在合理的时间内运行要容易得多。
获取这些“应用程序”之一的最终结果并在 SQL Server 2008 存储过程中使用它的最简单方法是什么?
其想法是将数据用于 Reporting Services 报告,而不是复制并粘贴到 Excel 中(手动操作)。需要可以在报表服务器上访问报表(不使用应用程序中的报表服务器控件)。
我可以输出 CSV 并通过命令行 exec 以某种方式读取它,但这看起来像是一个 hack。感谢您的帮助。
Note: I'm not trying to call a SQL Server stored proc using a L2SQL datacontext.
I use LINQPad for some fairly complex "reporting" that takes L2SQL output saved to an Array and is processed further.
For example, it's usually much easier to do multiple levels of grouping with LINQ to Objects instead of trying to optimize a T-SQL query to run in a reasonable amount of time.
What would be the easiest way to take the end result of one of these "applications" and use that in a SQL Server 2008 stored proc?
The idea is to use the data for a Reporting Services Report, rather than copying and pasting into Excel (manual labor). The reports need to be accessible on the report server (not using the Report Server control in an application).
I could output CSV and read that somehow via command line exec, but that seems like a hack. Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有两种可能性,这两种可能性都要求您使用“原始”ADO.NET:
使用SqlBulkCopy 类将数据插入临时表(可以是临时表)并编写存储过程以从该表中读取;或
将数据写入
DataSet
或DataTable
并使用表值参数 将其传递到存储过程中。第二种方法比第一种方法“更干净”,但如果您有大量数据(超过数百行),则效果不佳。
There are two possibilities, both of which will require you to use "raw" ADO.NET:
Use the SqlBulkCopy class to insert the data into a staging table (could be a temp table) and code the Stored Procedure to read from that table; or
Write the data into a
DataSet
orDataTable
and use a Table-Valued Parameter to pass it into the Stored Procedure.The second approach is "cleaner" than the first, but won't perform as well if you have a very large amount of data (more than several hundred rows).
SQL Server 2005 及更高版本允许您在 .NET 中编写存储过程。这样您就可以在报表中使用 LINQ。
正式名称是“CLR 存储过程”。 此处这是一个很好的介绍。
SQL Server 2005 and later allow you to write stored procedures in .NET. That way you can use LINQ in a report.
The official name is "CLR Stored Procedure". Here's a nice introduction.