Example #1
0
 /// <summary>
 /// Loads from reader.
 /// </summary>
 /// <param name="dr">The dr.</param>
 /// <returns></returns>
 public override County LoadFromReader(System.Data.IDataReader dr)
 {
     return(new County
     {
         Name = dr.Guard <string>("NAME"),
         CountyFIPS = dr.Guard <string>("GEOID").PadLeft(5, '0'),
         CountySSA = dr.ColumnExists("SSA") ?
                     !string.IsNullOrEmpty(dr.Guard <string>("SSA")) ? dr.Guard <string>("SSA").PadLeft(3, '0') : null
                             : null,
         State = dr.Guard <string>("USPS")
     });
 }
Example #2
0
        public static T GetNoCachingAs <T>(this System.Data.IDataReader reader)
        {
            // Create a new Object
            var newObjectToReturn = Activator.CreateInstance <T>();
            // Get all the properties in our Object
            var props = typeof(T).GetProperties();

            // For each property get the data from the reader to the object
            foreach (var t in props)
            {
                if (reader.ColumnExists(t.Name) && reader[t.Name] != DBNull.Value)
                {
                    typeof(T).InvokeMember(t.Name, BindingFlags.SetProperty, null, newObjectToReturn, new[] { reader[t.Name] });
                }
            }
            return(newObjectToReturn);
        }