Example #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);
                }
            }
        }
Example #2
0
        public EntityDescriptor(string moduleName, Type entityType, ISqlAdapter sqlAdapter, IEntitySqlBuilder sqlBuilder)
        {
            ModuleName = moduleName;

            SqlAdapter = sqlAdapter;

            EntityType = entityType;

            Database = sqlAdapter.Database;

            PrimaryKey = new PrimaryKeyDescriptor();

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

            SetTableName();

            SetIgnore();

            SetColumns();

            Sql = sqlBuilder.Build(this);

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