2010-07-08 20 views

cevap

8
using (var reader = cmd.ExecuteReader()) 
{ 
    var result = new List<Foo>(); 
    while (reader.Read()) 
    { 
     var foo = new Foo 
     { 
      Prop1 = reader.GetInt32(0), 
      Prop2 = reader.GetString(1), 
     } 
     result.Add(foo); 
    } 
} 
+0

Bu gibi ama 'result.Add tercih (yeni fan() {Prop1 = reader.GetInt32 (0), prop2 = reader.GetString (1)}); ' – Justin

0

Ayrıca, bu daha önce sorulan qestion kontrol edin: How can I easily convert DataReader to List<T>?

Kontrol bu jenerik türü için:

public ConvertToList<T>(SqlDataReader sqldr, int index) 
     { 
      List<T> list = new List<T>(); 

      while (sqldr.Read())   { 
       list.Add((T)sqldr.GetValue(index));    index++; 
      } 

      return list; 
     } 
0

Eski tartışma, ama boyutu için bu deneyin.

Alanlarınızı güçlü bir şekilde yazın ve satırlarınızı bir DbDataRecord nesnesine atın. ör

    Dim _Query = (From row In _Results.Cast(Of DbDataRecord)().AsParallel() 
          Select New uTyping.Profile() With { 
           .Id = row(0), 
           .Firstname = row(6) 
          }).ToList() 
İlgili konular