简体   繁体   English

存储过程中的Linq to SQL Select

[英]Linq to SQL Select in Stored Proc

I have a stored proc called via LINQ to SQL the stored proc calls another stored proc within it and has a SELECT to output the result. 我有一个通过LINQ to SQL调用的存储过程,该存储过程在其中调用了另一个存储过程,并且有一个SELECT输出结果。 the SELECT result doesnt' get returned to my LINQ to SQL, I can only get the int result value. SELECT结果没有返回到我的LINQ to SQL,我只能得到int结果值。 How can I get the select result of a stored proc with is within a stored proc 我如何获得存储过程的选择结果与存储过程中

The LINQ designer is not able to accurately parse your stored procedure to determine the schema. LINQ设计器无法准确地解析您的存储过程来确定模式。 One work around is to temporarily change your stored proc to a simple select of the proper schema. 一种解决方法是暂时将您存储的proc更改为适当模式的简单选择。 Remap it in the designer. 在设计器中重新映射它。 Then, change the stored proc back to the original. 然后,将存储的proc更改回原始。 This way the designer is able to figure out the schema and properly map it to the correct entity. 通过这种方式,设计人员能够找出模式并将其正确映射到正确的实体。

When you call the stored procedure from Sql Server Management Studio, does it return multiple rowsets? 当您从Sql Server Management Studio调用存储过程时,它是否返回多个行集?

If that's the case, using the stored procedure from LINQ is not trivial, see this article . 如果是这种情况,那么使用LINQ中的存储过程并不简单,请参阅本文

Reading multiple results is easy using the NextResult method from DataReader: 使用DataReader的Ne​​xtResult方法可以轻松读取多个结果:

var com = yourConnection.CreateCommand();
com.CommandText = "execute dbo.YourSp 'par1'";
var read = com.ExecuteReader();
// Move to second result set and read it
read.NextResult();
while (read.Read()) {
    Console.WriteLine(read["MyField"]);
}

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

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