mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-22 12:09:29 +08:00
db.InsertNav.IncludeByNameString
This commit is contained in:
@@ -13,7 +13,20 @@ namespace SqlSugar
|
||||
internal SqlSugarProvider Context { get; set; }
|
||||
internal InsertNavProvider<Root, Root> insertNavProvider { 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()
|
||||
{
|
||||
Check.ExceptionEasy(typeof(TChild).FullName.Contains("System.Collections.Generic.List`"), " need where T: class, new() ", "需要Class,new()约束,并且类属性中不能有required修饰符");
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user