예제 #1
0
        private static T WriteColumnMappings(T obj, IDataReader dr)
        {
            var entity       = new EntityInfo(typeof(T));
            var ReaderSchema = MappingCommon.ReadColumnInfo(dr.GetSchemaTable());

            foreach (var property in entity.Properties)
            {
                //  var columnMapping = entityParent.GetAttributDbColumn(property);
                if (!property.SetMethod.IsVirtual)
                {
                    var field = ReaderSchema.Where(O => O.ColumnName.ToString().ToUpper() == property.Name.ToString().ToUpper()).FirstOrDefault();
                    if (field != null)
                    {
                        var value = dr.GetValue(field.Ordinal);
                        if (value is DBNull)
                        {
                        }
                        else
                        {
                            try
                            {
                                property.SetValue(obj, GetValue(property, value));
                            }
                            catch (Exception ex)
                            {
                                throw new SystemException(ex.Message);
                            }
                        }
                    }
                }
            }

            return((T)obj);
        }
예제 #2
0
        public List <T> MappingWithoutInclud <T>(IDataReader dr)
        {
            ReaderSchema = MappingCommon.ReadColumnInfo(dr.GetSchemaTable());

            List <T> list = new List <T>();

            while (dr.Read())
            {
                T obj = default(T);
                obj = Activator.CreateInstance <T>();
                list.Add(WriteColumnMappings <T>(obj, dr));
            }
            return(list);
        }