Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement multiple result sets by Linq

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to achieve multiple result sets of Linq, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!

Linq multiple result sets

This stored procedure can generate multiple result set shapes for Linq, but we already know the order in which the results are returned.

The following is a stored procedure Get Customer And Orders that returns multiple result sets of Linq in sequence. Returns customers whose ID is "SEVES" and all their orders.

ALTER PROCEDURE [dbo]. [Get Customer And Orders] (@ CustomerID nchar (5))-Add the parameters for the stored procedure here AS BEGIN-- SET NOCOUNT ON added to prevent extra result sets from-- interfering with SELECT statements. SET NOCOUNT ON; SELECT * FROM Customers AS c WHERE c.CustomerID = @ CustomerID SELECT * FROM Orders AS o WHERE o.CustomerID = @ CustomerID END

Drag to the designer code as follows:

[Function (Name= "dbo. [Get Customer And Orders]")] public ISingleResult Get_Customer_And_Orders ([Parameter (Name= "CustomerID", DbType= "NChar (5)")] string customerID) {IExecuteResult result = this.ExecuteMethodCall (this, ((MethodInfo) (MethodInfo.GetCurrentMethod ()), customerID); return ((ISingleResult) (result.ReturnValue));}

Again, we want to modify the automatically generated code:

[Function (Name= "dbo. [Get Customer And Orders]")] [ResultType (typeof (CustomerResultSet))] [ResultType (typeof (OrdersResultSet))] public IMultipleResults Get_Customer_And_Orders ([Parameter (Name= "CustomerID", DbType= "NChar (5)")] string customerID) {IExecuteResult result = this.ExecuteMethodCall (this, (MethodInfo) (MethodInfo.GetCurrentMethod ()), customerID); return ((IMultipleResults) (result.ReturnValue));}

Similarly, write your own classes and have their stored procedures return their respective result sets.

IMultipleResults result = db.Get_Customer_And_Orders ("SEVES"); / return Customer result set IEnumerable customer = result.GetResult (); / / return Orders result set IEnumerable orders = result.GetResult (); / / here, we read the data foreach (CustomerResultSet cust in customer) {Console.WriteLine (cust.CustomerID);} in CustomerResultSet

Statement description: this example uses stored procedures to return the customer "SEVES" and all its orders

These are all the contents of the article "how to achieve multiple result sets in Linq". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report