Browse Source

Synchronization code

pull/40/head
sunkaixuan 1 year ago
parent
commit
ca73e484c3
  1. 11
      Src/Asp.NetCore2/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs
  2. 8
      Src/Asp.NetCore2/SqlSugar/Abstract/DynamicBuilder/Helper.cs
  3. 1
      Src/Asp.NetCore2/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs
  4. 12
      Src/Asp.NetCore2/SqlSugar/Abstract/InsertableProvider/InsertableHelper.cs
  5. 14
      Src/Asp.NetCore2/SqlSugar/Entities/DiscriminatorObject .cs
  6. 1
      Src/Asp.NetCore2/SqlSugar/Entities/EntityInfo.cs
  7. 1
      Src/Asp.NetCore2/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs

11
Src/Asp.NetCore2/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs

@ -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];

8
Src/Asp.NetCore2/SqlSugar/Abstract/DynamicBuilder/Helper.cs

@ -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;
}

1
Src/Asp.NetCore2/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs

@ -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())

12
Src/Asp.NetCore2/SqlSugar/Abstract/InsertableProvider/InsertableHelper.cs

@ -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

@ -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; }
}
}

1
Src/Asp.NetCore2/SqlSugar/Entities/EntityInfo.cs

@ -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; }
}
}

1
Src/Asp.NetCore2/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs

@ -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…
Cancel
Save