Beispiel #1
0
        public T WriteColumnMappings <T>(object obj, IDataReader dr)
        {
            ReaderSchema = MappingCommon.ReadColumnInfo(dr.GetSchemaTable());
            foreach (var property in entityParent.Properties)
            {
                var columnMapping = entityParent.GetAttributDbColumn(property);

                if (columnMapping != null)
                {
                    var field = ReaderSchema.Where(O => O.ColumnName.ToString().ToUpper() == columnMapping.ToString().ToUpper()).FirstOrDefault();
                    if (field != null)
                    {
                        var value = dr.GetValue(field.Ordinal);
                        if (value is DBNull)
                        {
                        }
                        else
                        {
                            try
                            {
                                property.SetValue(obj, this.GetValue(property, value));
                            }
                            catch (Exception ex)
                            {
                                throw new SystemException(ex.Message);
                            }
                        }
                    }
                }
            }

            return((T)obj);
        }
Beispiel #2
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);
        }