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

                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 != null && !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);
        }
Beispiel #3
0
        public List <T> MappingWithoutInclud <T>(IDataReader dr)
        {
            List <T> list = new List <T>();

            ReaderSchema = MappingCommon.ReadColumnInfo(dr.GetSchemaTable());
            while (dr.Read())
            {
                T obj = default(T);
                obj = Activator.CreateInstance <T>();

                foreach (var property in entityParent.Properties)
                {
                    var columnMapping = property.Name;
                    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);
                                }
                            }
                        }
                    }
                }

                var res = (T)obj;

                list.Add(res);
            }
            return(list);
        }