コード例 #1
0
        /// <summary>
        /// 设置属性列表
        /// </summary>
        private void SetColumns()
        {
            Columns = new ColumnDescriptorCollection();

            //加载属性列表
            var properties = new List <PropertyInfo>();

            foreach (var p in EntityType.GetProperties())
            {
                var type = p.PropertyType;
                if ((!type.IsGenericType || type.IsNullable()) && (type == typeof(Guid) || type.IsNullable() || Type.GetTypeCode(type) != TypeCode.Object) &&
                    Attribute.GetCustomAttributes(p).All(attr => attr.GetType() != typeof(IgnoreAttribute)))
                {
                    properties.Add(p);
                }
            }

            foreach (var p in properties)
            {
                var column = new ColumnDescriptor(p);
                if (column.IsPrimaryKey)
                {
                    PrimaryKey = new PrimaryKeyDescriptor(p);
                    Columns.Insert(0, column);
                }
                else
                {
                    Columns.Add(column);
                }
            }
        }
コード例 #2
0
        public EntityDescriptor(Type entityType, ISqlAdapter sqlAdapter, IEntitySqlBuilder sqlBuilder)
        {
            SqlAdapter = sqlAdapter;

            EntityType = entityType;

            Database = sqlAdapter.Database;

            PrimaryKey = new PrimaryKeyDescriptor();

            SoftDelete = EntityType.IsSubclassOfGeneric(typeof(EntityWithSoftDelete <,>));

            SetTableName();

            SetColumns();

            Sql = sqlBuilder.Build(this);

            IsEntityBase = EntityType.IsSubclassOfGeneric(typeof(EntityBase <>)) || EntityType.IsSubclassOfGeneric(typeof(EntityBaseWithSoftDelete <,>));
        }