This question has been asked by the customer many times. I think it is a small one, but it may be helpful to everyone. I will write it down and share it with you by the way.
The problem is that many customers don't know how to accept returned result sets when calling a stored procedure in a LINQ-SQL. So many people have done this. Of course, it seems understandable:
Sampledatacontext Test = New Sampledatacontext ();
Ienumerable < Tab1 > Retval = Test. Sp (); // Error here!
However, an error occurs during compilation and a type conversion error is reported. In fact, when calling SP in the LINQ-SQL, The LINQ-SQL will automatically generate a type for the returned result set, the type name is composed of SP name + "result. If the SP name is SP, the generated type is spresult. The result set returned when the SP is called is isingleresult <spresult>. As to why a type conversion error is reported, isingleresult <t> and ienumerable <t> cannot convert each other.
Now everyone should know how to do it? Try:Code:
Sampledatacontext Test = New Sampledatacontext ();
Isinlgeresult < Spresult > Retvalue = Test. Sp ();
Foreach (Spresult Value In Retvalue)
{
String Field = Value. field;
}
Knowing how to do it is far from enough, we suggest you look at the LINQ-SQL automatically generated code. If you have such a habit, you can easily solve the problem yourself. But there is also a small bug in the LINQ-SQL, as singleresult implies, it cannot generate multipleresults for us, such as when SP contains two select statements. If this happens, please leave a message. I will post the solution and start working now :)
Have a nice day!