Ejemplo n.º 1
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="row">数据行</param>
        /// <param name="columns">列集合</param>
        /// <returns>数据表实体</returns>
        protected override T CreateEntity(DataRow row, DataColumnCollection columns)
        {
            T entity = new T();

            PropertyInfo[] props = this._entityType.GetProperties();

            foreach (PropertyInfo prop in props)
            {
                DatabaseColumnAtrribute attr = null;

                if (this._columns.TryGetValue(prop.Name, out attr) && attr != null)
                {
                    DbType dbType = (attr.DbType.HasValue ? attr.DbType.Value : DbTypeHelper.InternalGetDbType(prop.PropertyType));
                    Object value;

                    if (this.IsNullableType(prop.PropertyType))
                    {
                        value = this.LoadNullableValue(row, columns, attr.ColumnName, dbType);
                    }
                    else
                    {
                        value = this.LoadValue(row, columns, attr.ColumnName, dbType);
                    }

                    prop.SetValue(entity, value, null);
                }
            }

            return(entity);
        }
Ejemplo n.º 2
0
        private Dictionary <String, DatabaseColumnAtrribute> GetTableColumns()
        {
            Dictionary <String, DatabaseColumnAtrribute> dict = new Dictionary <String, DatabaseColumnAtrribute>();

            PropertyInfo[] props = this._entityType.GetProperties();

            foreach (PropertyInfo prop in props)
            {
                Object[] objs = prop.GetCustomAttributes(typeof(DatabaseColumnAtrribute), true);

                foreach (Object obj in objs)
                {
                    DatabaseColumnAtrribute attr = obj as DatabaseColumnAtrribute;

                    if (attr != null)
                    {
                        dict[prop.Name] = attr;
                        break;
                    }
                }
            }

            return(dict);
        }