I have some objects that implement this interface:
public interface IRow { void Fill(DataRow dr); }
Usually, when I select something from db, I go:
public IEnumerable<IRow> SelectSomeRows { DataTable table = GetTableFromDatabase(); foreach (DataRow dr in table.Rows) { IRow row = new MySQLRow();
Now with .Net 4, I would like to use AsParallel and therefore LINQ.
I did some testing on it and it speeds up significantly (IRow.Fill uses Reflection, so it is very processor dependent)
In any case, my problem is, how can I create a LINQ query that calls Fills as part of the query, so is it parallelized correctly?
For performance testing, I created a constructor that took a DataRow as an argument, but I would really like to avoid this if possible.
With the constructor in place, it is obviously quite simple:
public IEnumerable<IRow> SelectSomeRowsParallel { DataTable table = GetTableFromDatabase(); return from DataRow dr in table.Rows.AsParallel() select new MySQLRow(dr); }
However, as I said, I would really like to just populate my Fill method in the LINQ query and, therefore, do not need to overload the constructor.