ICodeFirst add GetConfigEntity

This commit is contained in:
28810 2019-02-22 09:16:07 +08:00
parent be84f6dbd6
commit fb1871e558
9 changed files with 28 additions and 2 deletions

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>0.1.1</Version>
<Version>0.1.2</Version>
<Authors>YeXiangQin</Authors>
<Description>打造 .NETCore 最方便的 ORMDbFirst 与 CodeFirst 混合使用,提供从实体同步数据库,或者从数据库生成实体代码,支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库。</Description>
<PackageProjectUrl>https://github.com/2881099/FreeSql</PackageProjectUrl>

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>0.1.1</Version>
<Version>0.1.2</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors>
<Description>打造 .NETCore 最方便的 ORMDbFirst 与 CodeFirst 混合使用,提供从实体同步数据库,或者从数据库生成实体代码,支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库。</Description>

View File

@ -53,7 +53,25 @@ namespace FreeSql {
/// <param name="type"></param>
/// <returns></returns>
(int type, string dbtype, string dbtypeFull, bool? isnullable, object defaultValue)? GetDbInfo(Type type);
/// <summary>
/// 在外部配置实体的特性
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entity"></param>
/// <returns></returns>
ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity);
/// <summary>
/// 在外部配置实体的特性
/// </summary>
/// <param name="type"></param>
/// <param name="entity"></param>
/// <returns></returns>
ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity);
/// <summary>
/// 获取在外部配置实体的特性
/// </summary>
/// <param name="type"></param>
/// <returns>未使用ConfigEntity配置时返回null</returns>
TableAttribute GetConfigEntity(Type type);
}
}

View File

@ -50,6 +50,9 @@ namespace FreeSql.Internal {
Utils.GetTableByEntity(type, this, true); //update cache
return _orm.CodeFirst;
}
internal TableAttribute GetConfigEntity(Type type) {
return dicConfigEntity.TryGetValue(type, out var trytb) ? trytb : null;
}
internal TableAttribute GetEntityTableAttribute(Type type) {
var attr = type.GetCustomAttributes(typeof(TableAttribute), false).LastOrDefault() as TableAttribute;
if (dicConfigEntity.TryGetValue(type, out var trytb) == false) return attr;

View File

@ -274,5 +274,6 @@ where a.table_schema in ({0}) and a.table_name in ({1})".FormatMySql(tboldname ?
}
public ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity) => _commonUtils.ConfigEntity(entity);
public ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity) => _commonUtils.ConfigEntity(type, entity);
public TableAttribute GetConfigEntity(Type type) => _commonUtils.GetConfigEntity(type);
}
}

View File

@ -312,5 +312,6 @@ where owner={{0}} and table_name={{1}}".FormatOracleSQL(tboldname ?? tbname);
}
public ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity) => _commonUtils.ConfigEntity(entity);
public ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity) => _commonUtils.ConfigEntity(type, entity);
public TableAttribute GetConfigEntity(Type type) => _commonUtils.GetConfigEntity(type);
}
}

View File

@ -326,5 +326,6 @@ where pg_namespace.nspname={0} and pg_class.relname={1} and pg_constraint.contyp
}
public ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity) => _commonUtils.ConfigEntity(entity);
public ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity) => _commonUtils.ConfigEntity(type, entity);
public TableAttribute GetConfigEntity(Type type) => _commonUtils.GetConfigEntity(type);
}
}

View File

@ -284,5 +284,6 @@ use " + database, tboldname ?? tbname);
}
public ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity) => _commonUtils.ConfigEntity(entity);
public ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity) => _commonUtils.ConfigEntity(type, entity);
public TableAttribute GetConfigEntity(Type type) => _commonUtils.GetConfigEntity(type);
}
}

View File

@ -242,5 +242,6 @@ namespace FreeSql.Sqlite {
}
public ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity) => _commonUtils.ConfigEntity(entity);
public ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity) => _commonUtils.ConfigEntity(type, entity);
public TableAttribute GetConfigEntity(Type type) => _commonUtils.GetConfigEntity(type);
}
}