1. 程式人生 > 其它 >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 }