Synchronization code

This commit is contained in:
sunkaixuan
2023-09-11 01:35:26 +08:00
parent 263e9b6091
commit 5212c1be3c
2 changed files with 67 additions and 1 deletions

View File

@@ -13,7 +13,20 @@ namespace SqlSugar
internal SqlSugarProvider Context { get; set; } internal SqlSugarProvider Context { get; set; }
internal InsertNavProvider<Root, Root> insertNavProvider { get; set; } internal InsertNavProvider<Root, Root> insertNavProvider { get; set; }
internal NavContext NavContext { get; set; } internal NavContext NavContext { get; set; }
public InsertNavMethodInfo IncludeByNameString(string navMemberName, UpdateNavOptions updateNavOptions = null)
{
InsertNavMethodInfo result = new InsertNavMethodInfo();
result.Context = insertNavProvider._Context;
var entityInfo = result.Context.EntityMaintenance.GetEntityInfo<T>();
Type properyItemType;
bool isList;
Expression exp = UtilMethods.GetIncludeExpression(navMemberName, entityInfo, out properyItemType, out isList);
var method = this.GetType().GetMyMethod("Include", 2, isList)
.MakeGenericMethod(properyItemType);
var obj = method.Invoke(this, new object[] { exp, updateNavOptions });
result.MethodInfos = obj;
return result;
}
public InsertNavTask<Root, TChild> Include<TChild>(Expression<Func<Root, TChild>> expression) where TChild : class, new() 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修饰符"); Check.ExceptionEasy(typeof(TChild).FullName.Contains("System.Collections.Generic.List`"), " need where T: class, new() ", "需要Class,new()约束并且类属性中不能有required修饰符");

View File

@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
public class InsertNavMethodInfo
{
internal object MethodInfos { get; set; }
internal SqlSugarProvider Context { get; set; }
public InsertNavMethodInfo IncludeByNameString(string navMemberName, UpdateNavOptions updateNavOptions = null)
{
var type = MethodInfos.GetType().GetGenericArguments()[0];
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(type);
Type properyItemType;
bool isList;
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 });
this.MethodInfos = obj;
return this;
}
public InsertNavMethodInfo ThenIncludeByNameString(string navMemberName, UpdateNavOptions updateNavOptions = null)
{
var type = MethodInfos.GetType().GetGenericArguments()[0];
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(type);
Type properyItemType;
bool isList;
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 });
this.MethodInfos = obj;
return this;
}
public async Task<bool> ExecuteCommandAsync()
{
if (Context == null) return false;
var result = MethodInfos.GetType().GetMethod("ExecuteCommandAsync").Invoke(MethodInfos, new object[] { });
return await (Task<bool>)result;
}
public bool ExecuteCommand()
{
if (Context == null) return false;
var result = MethodInfos.GetType().GetMethod("ExecuteCommand").Invoke(MethodInfos, new object[] { });
return (bool)result;
}
}
}