- 增加 TableAttribute 特性属性 DisableSyncStructure,当实体对应的是视图时,可使用本功能禁用迁移 #61;

- 增加 FreeSqlBuilder UseEntityPropertyNameConvert() 全局转换实体属性名方法 #60;
This commit is contained in:
28810
2019-06-13 20:04:08 +08:00
parent ab658ca49e
commit 38d51a809d
18 changed files with 180 additions and 79 deletions

View File

@ -45,9 +45,9 @@ namespace FreeSql.Internal.CommonProvider {
internal ConcurrentDictionary<string, bool> dicSyced = new ConcurrentDictionary<string, bool>();
public bool SyncStructure<TEntity>() => this.SyncStructure(typeof(TEntity));
public bool SyncStructure(params Type[] entityTypes) {
if (entityTypes == null) return true;
var syncTypes = entityTypes.Where(a => dicSyced.ContainsKey(a.FullName) == false).ToArray();
if (syncTypes.Any() == false) return true;
if (entityTypes == null) return false;
var syncTypes = entityTypes.Where(a => dicSyced.ContainsKey(a.FullName) == false && GetTableByEntity(a)?.DisableSyncStructure == false).ToArray();
if (syncTypes.Any() == false) return false;
var before = new Aop.SyncStructureBeforeEventArgs(entityTypes);
_orm.Aop.SyncStructureBefore?.Invoke(this, before);
Exception exception = null;

View File

@ -73,6 +73,8 @@ namespace FreeSql.Internal {
if (!string.IsNullOrEmpty(trytb.Name)) attr.Name = trytb.Name;
if (!string.IsNullOrEmpty(trytb.OldName)) attr.OldName = trytb.OldName;
if (!string.IsNullOrEmpty(trytb.SelectFilter)) attr.SelectFilter = trytb.SelectFilter;
if (trytb._DisableSyncStructure != null) attr._DisableSyncStructure = trytb.DisableSyncStructure;
}
var attrs = type.GetCustomAttributes(typeof(TableAttribute), false);
foreach (var tryattrobj in attrs) {
@ -81,10 +83,12 @@ namespace FreeSql.Internal {
if (!string.IsNullOrEmpty(tryattr.Name)) attr.Name = tryattr.Name;
if (!string.IsNullOrEmpty(tryattr.OldName)) attr.OldName = tryattr.OldName;
if (!string.IsNullOrEmpty(tryattr.SelectFilter)) attr.SelectFilter = tryattr.SelectFilter;
if (tryattr._DisableSyncStructure != null) attr._DisableSyncStructure = tryattr.DisableSyncStructure;
}
if (!string.IsNullOrEmpty(attr.Name)) return attr;
if (!string.IsNullOrEmpty(attr.OldName)) return attr;
if (!string.IsNullOrEmpty(attr.SelectFilter)) return attr;
if (attr._DisableSyncStructure != null) return attr;
return null;
}
public ColumnAttribute GetEntityColumnAttribute(Type type, PropertyInfo proto) {

View File

@ -18,6 +18,7 @@ namespace FreeSql.Internal.Model {
public string DbName { get; set; }
public string DbOldName { get; set; }
public string SelectFilter { get; set; }
public bool DisableSyncStructure { get; set; }
public ColumnInfo VersionColumn { get; set; }

View File

@ -53,6 +53,7 @@ namespace FreeSql.Internal {
trytb.DbOldName = trytb.DbOldName?.ToUpper();
}
trytb.SelectFilter = tbattr?.SelectFilter;
if (tbattr != null) trytb.DisableSyncStructure = tbattr.DisableSyncStructure;
var propsLazy = new List<(PropertyInfo, bool, bool)>();
var propsNavObjs = new List<PropertyInfo>();
foreach (var p in trytb.Properties.Values) {