I have a couple helper methods that I use all the time during my data access layer. I figured I might as well post them and hopefully help others out.
I use the code from this article to pull my field names, that way I can build code like this:
public override IEntity PopulateFromOpenIDataReader(IDataReader dr)
{
const int ID = 0;
const int NAME = 1;
const int COMMENT = 2;
const int ADDRESS1 = 3;
const int ADDRESS2 = 4;
Doctor rv = new Doctor();
rv.ID = (int)DataValidation.GetValueFromDR(dr, ID, 0);
rv.StopName = DataValidation.GetValueFromDR(dr, NAME);
rv.Comment = DataValidation.GetValueFromDR(dr, COMMENT);
rv.Address.Address1 = DataValidation.GetValueFromDR(dr, ADDRESS1);
rv.Address.Address2 = DataValidation.GetValueFromDR(dr,ADDRESS2);
return rv;
}
The article with the DataValidation class code is here.