c# - Populate object list with datarow fields -


i wondering fastest , best practice way populate object list datatable data

currently i'm using method:

the object:

public class car {     public int carid { get; set; }     public string carname { get; set; }     public car(datarow row)     {         if (row != null)         {             this.carid = convert.toint32(row["car_id"]);             this.carname = row["car_name"].tostring();         }     } } 

the conversion:

public list<car> getcars(datatable cartable)     {         return cartable.select().selectasync(c => new car(c)).tolist();     } 

and async extension:

public static ienumerable<s> selectasync<t, s>(this ienumerable<t> query, func<t, s> expression)     {         taskfactory<s> tasks = new taskfactory<s>();         foreach (var item in query)         {             yield return tasks.startnew(() => expression(item)).result;         }     } 

i'm aware use "asparallel", tests i've made, method faster

but still, can me find faster way it? there design pattern that?

thank


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -