mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-22 20:13:41 +08:00
SplitTableAttribute(SplitType splitType,Type customSplitTableService)
This commit is contained in:
@@ -54,8 +54,10 @@ namespace SqlSugar
|
||||
var mappingInfo=this.Context.MappingTables.FirstOrDefault(it => it.EntityName == entityType.Name);
|
||||
if (mappingInfo == null)
|
||||
{
|
||||
UtilMethods.StartCustomSplitTable(this.Context,entityType);
|
||||
this.Context.CodeFirst.SplitTables().InitTables(entityType);
|
||||
this.Context.MappingTables.RemoveAll(it=>it.EntityName==entityType.Name);
|
||||
UtilMethods.EndCustomSplitTable(this.Context, entityType);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@@ -360,6 +360,7 @@ namespace SqlSugar
|
||||
var tables = getTableNamesFunc(helper.GetTables());
|
||||
result.Tables = tables;
|
||||
result.deleteobj = this;
|
||||
UtilMethods.StartCustomSplitTable(this.Context, typeof(T));
|
||||
return result;
|
||||
}
|
||||
public SplitTableDeleteByObjectProvider<T> SplitTable()
|
||||
@@ -373,6 +374,7 @@ namespace SqlSugar
|
||||
EntityInfo = this.EntityInfo
|
||||
};
|
||||
result.deleteobj = this;
|
||||
UtilMethods.StartCustomSplitTable(this.Context, typeof(T));
|
||||
return result;
|
||||
}
|
||||
public LogicDeleteProvider<T> IsLogic()
|
||||
|
@@ -665,6 +665,7 @@ namespace SqlSugar
|
||||
}
|
||||
public SplitInsertable<T> SplitTable(SplitType splitType)
|
||||
{
|
||||
UtilMethods.StartCustomSplitTable(this.Context, typeof(T));
|
||||
SplitTableContext helper = new SplitTableContext(Context)
|
||||
{
|
||||
EntityInfo = this.EntityInfo
|
||||
@@ -688,6 +689,7 @@ namespace SqlSugar
|
||||
|
||||
public SplitInsertable<T> SplitTable()
|
||||
{
|
||||
UtilMethods.StartCustomSplitTable(this.Context, typeof(T));
|
||||
var splitTableAttribute = typeof(T).GetCustomAttribute<SplitTableAttribute>();
|
||||
if (splitTableAttribute != null)
|
||||
{
|
||||
|
@@ -221,6 +221,7 @@ namespace SqlSugar
|
||||
}
|
||||
public SplitTableUpdateProvider<T> SplitTable(Func<List<SplitTableInfo>, IEnumerable<SplitTableInfo>> getTableNamesFunc)
|
||||
{
|
||||
UtilMethods.StartCustomSplitTable(this.Context, typeof(T));
|
||||
this.Context.MappingTables.Add(this.EntityInfo.EntityName, this.EntityInfo.DbTableName);
|
||||
SplitTableUpdateProvider<T> result = new SplitTableUpdateProvider<T>();
|
||||
result.Context = this.Context;
|
||||
@@ -235,6 +236,7 @@ namespace SqlSugar
|
||||
}
|
||||
public SplitTableUpdateByObjectProvider<T> SplitTable()
|
||||
{
|
||||
UtilMethods.StartCustomSplitTable(this.Context, typeof(T));
|
||||
Check.ExceptionEasy(UpdateParameterIsNull, "SplitTable() not supported db.Updateable<T>(),use db.Updateable(list)", ".SplitTable()不支持 db.Updateable<T>()方式更新,请使用 db.Updateable(list) 对象方式更新, 或者使用 .SplitTable(+1)重载");
|
||||
SplitTableUpdateByObjectProvider<T> result = new SplitTableUpdateByObjectProvider<T>();
|
||||
result.Context = this.Context;
|
||||
|
@@ -10,10 +10,20 @@ namespace SqlSugar
|
||||
public class SplitTableAttribute : Attribute
|
||||
{
|
||||
public SplitType SplitType { get; set; }
|
||||
public Type CustomSplitTableService { get; set; }
|
||||
public SplitTableAttribute(SplitType splitType)
|
||||
{
|
||||
this.SplitType = splitType;
|
||||
}
|
||||
public SplitTableAttribute(SplitType splitType,Type customSplitTableService)
|
||||
{
|
||||
this.SplitType = splitType;
|
||||
if (!customSplitTableService.GetInterfaces().Any(it => it == typeof(ISplitTableService)))
|
||||
{
|
||||
Check.ExceptionEasy("customSplitTableService in SplitTableAttribute(SplitType splitType,Type customSplitTableService) must be inherited ISplitTableService", " SplitTableAttribute(SplitType splitType,Type customSplitTableService) 中的 customSplitTableService 必须继承 ISplitTableService");
|
||||
}
|
||||
this.CustomSplitTableService= customSplitTableService;
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property, Inherited = true)]
|
||||
|
@@ -17,6 +17,24 @@ namespace SqlSugar
|
||||
{
|
||||
public class UtilMethods
|
||||
{
|
||||
internal static void EndCustomSplitTable(ISqlSugarClient context,Type entityType)
|
||||
{
|
||||
var splitTableAttribute = entityType.GetCustomAttribute<SplitTableAttribute>();
|
||||
if (splitTableAttribute.CustomSplitTableService != null)
|
||||
{
|
||||
context.CurrentConnectionConfig.ConfigureExternalServices.SplitTableService = null;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void StartCustomSplitTable(ISqlSugarClient context, Type entityType)
|
||||
{
|
||||
var splitTableAttribute = entityType.GetCustomAttribute<SplitTableAttribute>();
|
||||
if (splitTableAttribute.CustomSplitTableService != null)
|
||||
{
|
||||
context.CurrentConnectionConfig.ConfigureExternalServices.SplitTableService
|
||||
= (ISplitTableService)Activator.CreateInstance(splitTableAttribute.CustomSplitTableService);
|
||||
}
|
||||
}
|
||||
public static void ConvertParameter(SugarParameter p, ISqlBuilder builder)
|
||||
{
|
||||
if (!p.ParameterName.StartsWith(builder.SqlParameterKeyWord))
|
||||
|
Reference in New Issue
Block a user