diff --git a/FreeSql.Repository/FreeSql.Repository.csproj b/FreeSql.Repository/FreeSql.Repository.csproj index 9834bfea..ad9d309f 100644 --- a/FreeSql.Repository/FreeSql.Repository.csproj +++ b/FreeSql.Repository/FreeSql.Repository.csproj @@ -2,7 +2,7 @@ netstandard2.0 - 0.1.1 + 0.1.2 YeXiangQin 打造 .NETCore 最方便的 ORM,DbFirst 与 CodeFirst 混合使用,提供从实体同步数据库,或者从数据库生成实体代码,支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库。 https://github.com/2881099/FreeSql diff --git a/FreeSql/FreeSql.csproj b/FreeSql/FreeSql.csproj index 56ddc43a..bc1cfe4c 100644 --- a/FreeSql/FreeSql.csproj +++ b/FreeSql/FreeSql.csproj @@ -2,7 +2,7 @@ netstandard2.0 - 0.1.1 + 0.1.2 true YeXiangQin 打造 .NETCore 最方便的 ORM,DbFirst 与 CodeFirst 混合使用,提供从实体同步数据库,或者从数据库生成实体代码,支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库。 diff --git a/FreeSql/Interface/ICodeFirst.cs b/FreeSql/Interface/ICodeFirst.cs index 972eb69d..e9807b11 100644 --- a/FreeSql/Interface/ICodeFirst.cs +++ b/FreeSql/Interface/ICodeFirst.cs @@ -53,7 +53,25 @@ namespace FreeSql { /// /// (int type, string dbtype, string dbtypeFull, bool? isnullable, object defaultValue)? GetDbInfo(Type type); + /// + /// 在外部配置实体的特性 + /// + /// + /// + /// ICodeFirst ConfigEntity(Action> entity); + /// + /// 在外部配置实体的特性 + /// + /// + /// + /// ICodeFirst ConfigEntity(Type type, Action entity); + /// + /// 获取在外部配置实体的特性 + /// + /// + /// 未使用ConfigEntity配置时,返回null + TableAttribute GetConfigEntity(Type type); } } diff --git a/FreeSql/Internal/CommonUtils.cs b/FreeSql/Internal/CommonUtils.cs index 8d48cebe..5112f127 100644 --- a/FreeSql/Internal/CommonUtils.cs +++ b/FreeSql/Internal/CommonUtils.cs @@ -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; diff --git a/FreeSql/MySql/MySqlCodeFirst.cs b/FreeSql/MySql/MySqlCodeFirst.cs index df1839c0..d6261e83 100644 --- a/FreeSql/MySql/MySqlCodeFirst.cs +++ b/FreeSql/MySql/MySqlCodeFirst.cs @@ -274,5 +274,6 @@ where a.table_schema in ({0}) and a.table_name in ({1})".FormatMySql(tboldname ? } public ICodeFirst ConfigEntity(Action> entity) => _commonUtils.ConfigEntity(entity); public ICodeFirst ConfigEntity(Type type, Action entity) => _commonUtils.ConfigEntity(type, entity); + public TableAttribute GetConfigEntity(Type type) => _commonUtils.GetConfigEntity(type); } } \ No newline at end of file diff --git a/FreeSql/Oracle/OracleCodeFirst.cs b/FreeSql/Oracle/OracleCodeFirst.cs index f090e8e3..4be036aa 100644 --- a/FreeSql/Oracle/OracleCodeFirst.cs +++ b/FreeSql/Oracle/OracleCodeFirst.cs @@ -312,5 +312,6 @@ where owner={{0}} and table_name={{1}}".FormatOracleSQL(tboldname ?? tbname); } public ICodeFirst ConfigEntity(Action> entity) => _commonUtils.ConfigEntity(entity); public ICodeFirst ConfigEntity(Type type, Action entity) => _commonUtils.ConfigEntity(type, entity); + public TableAttribute GetConfigEntity(Type type) => _commonUtils.GetConfigEntity(type); } } \ No newline at end of file diff --git a/FreeSql/PostgreSQL/PostgreSQLCodeFirst.cs b/FreeSql/PostgreSQL/PostgreSQLCodeFirst.cs index fd8f8703..febf2e73 100644 --- a/FreeSql/PostgreSQL/PostgreSQLCodeFirst.cs +++ b/FreeSql/PostgreSQL/PostgreSQLCodeFirst.cs @@ -326,5 +326,6 @@ where pg_namespace.nspname={0} and pg_class.relname={1} and pg_constraint.contyp } public ICodeFirst ConfigEntity(Action> entity) => _commonUtils.ConfigEntity(entity); public ICodeFirst ConfigEntity(Type type, Action entity) => _commonUtils.ConfigEntity(type, entity); + public TableAttribute GetConfigEntity(Type type) => _commonUtils.GetConfigEntity(type); } } \ No newline at end of file diff --git a/FreeSql/SqlServer/SqlServerCodeFirst.cs b/FreeSql/SqlServer/SqlServerCodeFirst.cs index f9b256b8..967f3d95 100644 --- a/FreeSql/SqlServer/SqlServerCodeFirst.cs +++ b/FreeSql/SqlServer/SqlServerCodeFirst.cs @@ -284,5 +284,6 @@ use " + database, tboldname ?? tbname); } public ICodeFirst ConfigEntity(Action> entity) => _commonUtils.ConfigEntity(entity); public ICodeFirst ConfigEntity(Type type, Action entity) => _commonUtils.ConfigEntity(type, entity); + public TableAttribute GetConfigEntity(Type type) => _commonUtils.GetConfigEntity(type); } } \ No newline at end of file diff --git a/FreeSql/Sqlite/SqliteCodeFirst.cs b/FreeSql/Sqlite/SqliteCodeFirst.cs index 3b109abf..7ea734e5 100644 --- a/FreeSql/Sqlite/SqliteCodeFirst.cs +++ b/FreeSql/Sqlite/SqliteCodeFirst.cs @@ -242,5 +242,6 @@ namespace FreeSql.Sqlite { } public ICodeFirst ConfigEntity(Action> entity) => _commonUtils.ConfigEntity(entity); public ICodeFirst ConfigEntity(Type type, Action entity) => _commonUtils.ConfigEntity(type, entity); + public TableAttribute GetConfigEntity(Type type) => _commonUtils.GetConfigEntity(type); } } \ No newline at end of file