Synchronization code

This commit is contained in:
sunkaixuan 2024-05-08 16:53:44 +08:00
parent 9b4162d840
commit 8aca0f0f2b
2 changed files with 20 additions and 4 deletions

View File

@ -43,6 +43,22 @@ namespace SqlSugar
}
return methodInfo;
}
public InsertNavMethodInfo IncludesAllFirstLayer(InsertNavOptions insertNavOptions,params string[] ignoreColumns)
{
if (ignoreColumns == null)
{
ignoreColumns = new string[] { };
}
this.Context = insertNavProvider._Context;
var navColumns = this.Context.EntityMaintenance.GetEntityInfo<Root>().Columns.Where(it => !ignoreColumns.Contains(it.PropertyName) || !ignoreColumns.Any(z => z.EqualCase(it.DbColumnName))).Where(it => it.Navigat != null).ToList();
var updateNavs = this;
InsertNavMethodInfo methodInfo = updateNavs.IncludeByNameString(navColumns[0].PropertyName);
foreach (var item in navColumns.Skip(1))
{
methodInfo = methodInfo.IncludeByNameString(item.PropertyName, insertNavOptions);
}
return methodInfo;
}
public InsertNavTask<Root, TChild> Include<TChild>(Expression<Func<Root, TChild>> expression) where TChild : class, new()
{
Check.ExceptionEasy(typeof(TChild).FullName.Contains("System.Collections.Generic.List`"), " need where T: class, new() ", "需要Class,new()约束并且类属性中不能有required修饰符");

View File

@ -11,7 +11,7 @@ namespace SqlSugar
internal object MethodInfos { get; set; }
internal SqlSugarProvider Context { get; set; }
public InsertNavMethodInfo IncludeByNameString(string navMemberName, InsertNavRootOptions updateNavOptions = null)
public InsertNavMethodInfo IncludeByNameString(string navMemberName, InsertNavOptions insertNavOptions = null)
{
var type = MethodInfos.GetType().GetGenericArguments()[0];
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(type);
@ -20,11 +20,11 @@ namespace SqlSugar
Expression exp = UtilMethods.GetIncludeExpression(navMemberName, entityInfo, out properyItemType, out isList);
var method = this.MethodInfos.GetType().GetMyMethod("Include", 2, isList)
.MakeGenericMethod(properyItemType);
var obj = method.Invoke(this.MethodInfos, new object[] { exp, updateNavOptions });
var obj = method.Invoke(this.MethodInfos, new object[] { exp, insertNavOptions });
this.MethodInfos = obj;
return this;
}
public InsertNavMethodInfo ThenIncludeByNameString(string navMemberName, InsertNavRootOptions updateNavOptions = null)
public InsertNavMethodInfo ThenIncludeByNameString(string navMemberName, InsertNavOptions insertNavOptions = null)
{
var type = MethodInfos.GetType().GetGenericArguments()[1];
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(type);
@ -33,7 +33,7 @@ namespace SqlSugar
Expression exp = UtilMethods.GetIncludeExpression(navMemberName, entityInfo, out properyItemType, out isList);
var method = this.MethodInfos.GetType().GetMyMethod("ThenInclude", 2, isList)
.MakeGenericMethod(properyItemType);
var obj = method.Invoke(this.MethodInfos, new object[] { exp, updateNavOptions });
var obj = method.Invoke(this.MethodInfos, new object[] { exp, insertNavOptions });
this.MethodInfos = obj;
return this;
}