Exemplo n.º 1
0
        public EntityDescriptor(ISqlAdapter sqlAdapter, IEntitySqlBuilder sqlBuilder)
        {
            SqlAdapter = sqlAdapter;

            EntityType = typeof(TEntity);

            PrimaryKey = new PrimaryKeyDescriptor();

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

            SetTableName();

            SetColumns();

            Sql = sqlBuilder.Build(this);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 设置属性列表
        /// </summary>
        private void SetColumns()
        {
            Columns = new ColumnDescriptorCollection();

            //加载属性列表
            var properties = EntityType.GetProperties().Where(p =>
                                                              !p.PropertyType.IsGenericType &&
                                                              (p.PropertyType == typeof(Guid) || Type.GetTypeCode(p.PropertyType) != TypeCode.Object) &&
                                                              Attribute.GetCustomAttributes(p).All(attr => attr.GetType() != typeof(IgnoreAttribute))).ToList();

            foreach (var p in properties)
            {
                var column = new ColumnDescriptorr(p);
                if (column.IsPrimaryKey)
                {
                    PrimaryKey = new PrimaryKeyDescriptor(p);
                    Columns.Insert(0, column);
                }
                else
                {
                    Columns.Add(column);
                }
            }
        }