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
Post a Comment