In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to achieve linq stored procedures to return multiple result sets, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.
By default, the code generated by the linq stored procedure is ISingleResult, that is, only one result set can be returned. We tampered with it and changed it to IMultipleResults. Entity classes change according to different circumstances.
Before the linq stored procedure changes:
[Function (Name= "dbo.MeterTaskStat")] public ISingleResult MeterTaskStat ([Parameter (Name= "MeterTaskType", DbType= "Int")] System.Nullable meterTaskType, [Parameter (Name= "StartDate", DbType= "DateTime")] System.Nullable startDate, [Parameter (Name= "EndDate", DbType= "DateTime")] System.Nullable endDate) {IExecuteResult result = this.ExecuteMethodCall (this, (MethodInfo) (MethodInfo.GetCurrentMethod ()), meterTaskType, startDate, endDate); return ((ISingleResult) (result.ReturnValue));}
After the linq stored procedure changes:
[Function (Name= "dbo.MeterTaskStat")] [ResultType (typeof (TaskStatData))] public IMultipleResults MeterTaskStat ([Parameter (Name= "MeterTaskType", DbType = "Int")] System.Nullable meterTaskType, [Parameter (Name= "StartDate", DbType = "DateTime")] System.Nullable startDate, [Parameter (Name= "EndDate", DbType = "DateTime")] System.Nullable endDate) {IExecuteResult result = this.ExecuteMethodCall (this, (MethodInfo) (MethodInfo.GetCurrentMethod ()), meterTaskType, startDate, endDate) Return ((IMultipleResults) (result.ReturnValue));
Notice one more item: the record of [ResultType (typeof (TaskStatData))]. Briefly, an entity type must be returned for the result of the linq stored procedure, and TaskStatData is the self-defined class. [ResultType (typeof (TaskStatData))] must be added, plus the linq stored procedure return value.
Linq stored procedures:
Set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go-Author:MaHong-- Create date: 2008-09-11-- Description: according to caliber statistics, water meter reassembly task information within a certain period of time-- = = ALTER PROCEDURE [dbo]. [MeterTaskStat] @ MeterTaskType INT, @ StartDate DateTime, @ EndDate DateTime AS BEGIN SET NOCOUNT ON SELECT MeterCaliberName,SUM (Requisition) AS RequisitionCount,SUM (Approve) AS ApproveCount, SUM (Disapprove) AS DisapproveCount,SUM (WaitWork) AS WaitWorkCount, SUM (CompleteY) AS CompleteYCount,SUM (CompleteN) AS CompleteNCount, SUM (Requisition+Approve+Disapprove+WaitWork+CompleteY+CompleteN) AS Subtotal FROM (SELECT MeterCaliberName, CASE WHEN MeterTaskStatus=0 THEN 1 ELSE 0 END Requisition, CASE WHEN MeterTaskStatus=1 THEN 1 ELSE 0 END Approve, CASE WHEN MeterTaskStatus=11 THEN 1 ELSE 0 END Disapprove, CASE WHEN MeterTaskStatus=2 THEN 1 ELSE 0 END WaitWork, CASE WHEN MeterTaskStatus=4 THEN 1 ELSE 0 END CompleteY CASE WHEN MeterTaskStatus=5 THEN 1 ELSE 0 END CompleteN FROM View_MeterTaskMaintain WHERE [MeterTaskType] = @ MeterTaskType AND StartDate BETWEEN @ StartDate AND @ EndDate) tempTable GROUP BY MeterCaliberName END
The linq stored procedure is called directly in the middle layer of business:
Public class StatTaskControl: ControlBase {public IEnumerable GetStatInfo (TaskType type, DateTime startDate, DateTime endDate) {IMultipleResults info = Context.MeterTaskStat ((int) type, startDate, endDate); IEnumerable data = info.GetResult (); return data;}}
Ui layer acquisition of linq stored procedures:
Protected void StatButton_Click (object sender, EventArgs e) {DateTime startDate = DateTime.Parse (StartDate.Text); DateTime endDate = DateTime.Parse (EndDate.Text); TaskType type = TaskType.Remove; IEnumerable info = _ control.GetStatInfo (type, startDate, endDate); List data = info.ToList (); RemoveGridView.DataSource = data; RemoveGridView.DataBind ();}
The whole linq stored procedure is just a few steps. It's not too difficult!
On how to achieve linq stored procedures to return multiple result sets to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.