How to convert sqldatareader to list of dto's?

前端 未结 3 1293
北荒
北荒 2021-01-22 03:28

I just started moving all my ado.net code from the asp.net pages to repo\'s and created dto\'s for each table (manually), but now I don\'t know what is a good efficient way to c

3条回答
  •  故里飘歌
    2021-01-22 04:07

    Usually the pattern looks something like:

    List list = new List();
    
    using(SqlDataReader rdr = GetReaderFromSomewhere()) {
      while(rdr.Read()) {
         Customer cust = new Customer();
         cust.Id = (int)rdr["Id"];
         list.Add(cust)
      }
    }
    

提交回复
热议问题