After upgrading to DNN 5.5.0 we had to implement IHydratable on all of our business objects.
This idea seemed like a good way to go at first, but after playing with IHydratable I'm not so sure any more.
There are two possibilities:
- I'm doing it wrong
IHydratableforces you to useselect *construct an all your queries
The business case:
- My first sproc returns the
BgIdandBgShortDesc - My second sproc returns
BgIdandBgReportedUser
My IHydratable is implemented as show below:
public class Bug : IHydratable
{
public int BgId { get; set; }
public string BgShortDesc { get; set; }
public int BgReportedUser { get; set; }
public DateTime BgReportedDate { get; set; }
public Bug() { }
public int KeyID
{
get { return BgId; }
set { BgId = value; }
}
public void Fill(IDataReader dr)
{
BgId = Convert.ToInt32(Null.SetNull(dr["BgId"], BgId));
BgShortDesc = Convert.ToString(Null.SetNull(dr["BgShortDesc"], BgShortDesc));
BgReportedUser = Convert.ToInt32(Null.SetNull(dr["BgReportedUser"], BgReportedUser));
BgReportedDate = Convert.ToDateTime(Null.SetNull(dr["BgReportedDate"], BgReportedDate));
}
}
The fill method will throw an IndexOutOfRangeException on any of the above sprocs, since not all the fields get returned with IDataReader.
The easy way around the problem is to use select * in all of the sprocs, but that's not a good practice.
What's the PROPER way of implementing IHydratable in this scenario?
P.S. keep in mind that my example is oversimplified to get the point across.