mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-15 14:04:44 +08:00
Synchronization code
This commit is contained in:
parent
9d690557ad
commit
ca73e484c3
@ -227,6 +227,17 @@ namespace SqlSugar
|
||||
protected virtual void Execute(Type entityType)
|
||||
{
|
||||
var entityInfo = this.Context.EntityMaintenance.GetEntityInfoNoCache(entityType);
|
||||
if (entityInfo.Discrimator.HasValue())
|
||||
{
|
||||
Check.ExceptionEasy(!Regex.IsMatch(entityInfo.Discrimator, @"^(?:\w+:\w+)(?:,\w+:\w+)*$"), "The format should be type:cat for this type, and if there are multiple, it can be FieldName:cat,FieldName2:dog ", "格式错误应该是type:cat这种格式,如果是多个可以FieldName:cat,FieldName2:dog,不要有空格");
|
||||
var array = entityInfo.Discrimator.Split(',');
|
||||
foreach (var disItem in array)
|
||||
{
|
||||
var name = disItem.Split(':').First();
|
||||
var value = disItem.Split(':').Last();
|
||||
entityInfo.Columns.Add(new EntityColumnInfo() { PropertyInfo=typeof(DiscriminatorObject).GetProperty(nameof(DiscriminatorObject.FieldName)),IsOnlyIgnoreUpdate = true, DbColumnName = name, UnderType = typeof(string), PropertyName = name, Length = 50 });
|
||||
}
|
||||
}
|
||||
if (this.MappingTables.ContainsKey(entityType))
|
||||
{
|
||||
entityInfo.DbTableName = this.MappingTables[entityType];
|
||||
|
@ -39,13 +39,17 @@ namespace SqlSugar
|
||||
attributeType.GetProperty(nameof(SugarTable.TableName)),
|
||||
attributeType.GetProperty(nameof(SugarTable.TableDescription)) ,
|
||||
attributeType.GetProperty(nameof(SugarTable.IsDisabledUpdateAll)) ,
|
||||
attributeType.GetProperty(nameof(SugarTable.IsDisabledDelete))
|
||||
attributeType.GetProperty(nameof(SugarTable.IsDisabledDelete)),
|
||||
attributeType.GetProperty(nameof(SugarTable.IsCreateTableFiledSort)),
|
||||
attributeType.GetProperty(nameof(SugarTable.Discrimator))
|
||||
}
|
||||
, new object[] {
|
||||
sugarTable.TableName,
|
||||
sugarTable.TableDescription ,
|
||||
sugarTable.IsDisabledUpdateAll,
|
||||
sugarTable.IsDisabledDelete
|
||||
sugarTable.IsDisabledDelete,
|
||||
sugarTable.IsCreateTableFiledSort,
|
||||
sugarTable.Discrimator
|
||||
});
|
||||
return attributeBuilder;
|
||||
}
|
||||
|
@ -62,6 +62,7 @@ namespace SqlSugar
|
||||
result.IsDisabledUpdateAll = sugarTable.IsDisabledUpdateAll;
|
||||
result.IsDisabledDelete = sugarTable.IsDisabledDelete;
|
||||
result.IsCreateTableFiledSort = sugarTable.IsCreateTableFiledSort;
|
||||
result.Discrimator = sugarTable.Discrimator;
|
||||
}
|
||||
var indexs = type.GetCustomAttributes(typeof(SugarIndexAttribute));
|
||||
if (indexs != null && indexs.Any())
|
||||
|
@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
@ -292,6 +293,17 @@ namespace SqlSugar
|
||||
}
|
||||
insertItem.Add(columnInfo);
|
||||
}
|
||||
if (EntityInfo.Discrimator.HasValue())
|
||||
{
|
||||
Check.ExceptionEasy(!Regex.IsMatch(EntityInfo.Discrimator, @"^(?:\w+:\w+)(?:,\w+:\w+)*$"), "The format should be type:cat for this type, and if there are multiple, it can be FieldName:cat,FieldName2:dog ", "格式错误应该是type:cat这种格式,如果是多个可以FieldName:cat,FieldName2:dog,不要有空格");
|
||||
var array = EntityInfo.Discrimator.Split(',');
|
||||
foreach (var disItem in array)
|
||||
{
|
||||
var name = disItem.Split(':').First();
|
||||
var value = disItem.Split(':').Last();
|
||||
insertItem.Add(new DbColumnInfo() { DbColumnName = name, PropertyName = name, PropertyType = typeof(string), Value = value });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string GetDbColumnName(string propertyName)
|
||||
|
14
Src/Asp.NetCore2/SqlSugar/Entities/DiscriminatorObject .cs
Normal file
14
Src/Asp.NetCore2/SqlSugar/Entities/DiscriminatorObject .cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public struct DiscriminatorObject
|
||||
{
|
||||
public string FieldName { get; set; }
|
||||
public string FieldValue { get; set; }
|
||||
}
|
||||
}
|
@ -19,5 +19,6 @@ namespace SqlSugar
|
||||
public bool IsDisabledUpdateAll { get; set; }
|
||||
public List<SugarIndexAttribute> Indexs { get; set; }
|
||||
public bool IsCreateTableFiledSort { get; set; }
|
||||
public string Discrimator { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ namespace SqlSugar
|
||||
public bool IsDisabledDelete { get; set; }
|
||||
public bool IsDisabledUpdateAll { get; set; }
|
||||
public bool IsCreateTableFiledSort { get; set; }
|
||||
public string Discrimator { get; set; }
|
||||
public SugarTable(string tableName) {
|
||||
this.TableName = tableName;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user