其他分享
首页 > 其他分享> > EF读取多个结果集

EF读取多个结果集

作者:互联网

 1 using (var command = CreateCommand(sql, CommandType.Text, parameters))
 2             {
 3                 using (var reader = await command.ExecuteReaderAsync())
 4                 {
 5                     var list = new List<CheckResultDto>();
 6                     var total = 0;
 7                     var i = 0;
 8                     //第一个结果集
 9                     while (reader.Read())
10                     {
11                         CheckResultDto dto = new CheckResultDto();
12                         dto.IsGroup = int.Parse(reader["IsGroup"].ToString()) == 1 ? true : false;
13                         dto.Name = reader["Name"].ToString();
14                         dto.Status = (TurnoverBoxStatusEnum)int.Parse(reader["Status"].ToString());
15                         dto.Path = reader["Path"].ToString();
16                         dto.Date = Convert.ToDateTime(reader["Date"].ToString());
17                         18                         dto.SortLine = reader["SortLine"].ToString();
19                         dto.RouteName = reader["RouteName"].ToString();
20                         dto.Code = reader["Code"].ToString();
21                         dto.BCode = reader["BCode"].ToString();
22                         list.Add(dto);
23                         if (i == 10)
24                         {
25                             total = int.Parse(reader["total"].ToString());
26                         }
27                         i++;
28                     }
29                     //第二个结果集
30                     reader.NextResult();
31                     while (reader.Read())
32                     {
33                         total = int.Parse(reader["total"].ToString());
34                     }
35 
36                         return list;
37                 }
38             }

 

标签:dto,读取,多个,int,EF,ToString,reader,var,total
来源: https://www.cnblogs.com/sugarwxx/p/16280122.html