/// <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.IsGuid() || 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, SqlAdapter); if (column.IsPrimaryKey) { PrimaryKey = new PrimaryKeyDescriptor(p); Columns.Insert(0, column); } else { Columns.Add(column); } } }
public EntityDescriptor(IDbContext dbContext, Type entityType) { DbContext = dbContext; DbOptions = dbContext.Options.DbModuleOptions; SqlAdapter = dbContext.Options.SqlAdapter; ModuleName = DbOptions.Name; EntityType = entityType; Database = SqlAdapter.Database; PrimaryKey = new PrimaryKeyDescriptor(); SoftDelete = EntityType.IsSubclassOfGeneric(typeof(EntityWithSoftDelete <,>)); SetTableName(); SetIgnore(); SetColumns(); var sqlBuilder = new EntitySqlBuilder(this, dbContext.Options.DbOptions); Sql = sqlBuilder.Build(); IsEntityBase = EntityType.IsSubclassOfGeneric(typeof(EntityBase <>)) || EntityType.IsSubclassOfGeneric(typeof(EntityBaseWithSoftDelete <,>)); IsTenant = typeof(ITenant).IsAssignableFrom(EntityType); }
public EntityDescriptor(DbModuleOptions dbOptions, Type entityType, ISqlAdapter sqlAdapter) { DbOptions = dbOptions; ModuleName = dbOptions.Name; SqlAdapter = sqlAdapter; EntityType = entityType; Database = sqlAdapter.Database; PrimaryKey = new PrimaryKeyDescriptor(); SoftDelete = EntityType.IsSubclassOfGeneric(typeof(EntityWithSoftDelete <,>)); SetTableName(); SetIgnore(); SetColumns(); var sqlBuilder = new EntitySqlBuilder(this); Sql = sqlBuilder.Build(); IsEntityBase = EntityType.IsSubclassOfGeneric(typeof(EntityBase <>)) || EntityType.IsSubclassOfGeneric(typeof(EntityBaseWithSoftDelete <,>)); }
public EntityDescriptor(DbOptions dbOptions, DbModuleOptions dbModuleOptions, Type entityType, ISqlAdapter sqlAdapter) { DbOptions = dbOptions; ModuleOptions = dbModuleOptions; ModuleName = dbModuleOptions.Name; SqlAdapter = sqlAdapter; EntityType = entityType; Database = sqlAdapter.Database; PrimaryKey = new PrimaryKeyDescriptor(); //实体基类 IsEntityBase = EntityType.GetInterfaces().Any(m => m == typeof(IBase)); //软删除 IsSoftDelete = EntityType.GetInterfaces().Any(m => m == typeof(ISoftDelete)); SetTableName(); SetIgnore(); SetColumns(); var sqlBuilder = new EntitySqlBuilder(this); Sql = sqlBuilder.Build(); }
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 <,>)); }