Luke Smith Write today, wrong tomorrow

Creating a generic list from a SqlDataReader v1.1

Since writing the PopulateList method
I've made a few improvements, with some pointers from Erik
Porter
.

Firstly the interfaces can be passed a generic type, meaning IObjectPopulator
can be set to return a type T instead of a object type saving a cast in the PopulateList<T>
method.

public interface IObjectPopulator<T>
{
   T Populate(IDataRecord
dr);
}

Erik
pointed me to using dr.GetOrdinal and the dr.Get*Type* methods inside the implementation
of the Populate(SqlDataReader) methods.

This
little helper method really has saved me quite alot of time writing the backend dataaccess,
and reduces the errors that copy and pasteing always introduces.

comments powered by Disqus