mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-22 20:13:41 +08:00
UpdateNav.IncludeByNameString
This commit is contained in:
@@ -59,6 +59,22 @@ namespace SqlSugar
|
|||||||
result.NavContext = UpdateNavProvider.NavContext;
|
result.NavContext = UpdateNavProvider.NavContext;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UpdateNavMethodInfo IncludeByNameString(string navMemberName, UpdateNavOptions updateNavOptions=null)
|
||||||
|
{
|
||||||
|
UpdateNavMethodInfo result = new UpdateNavMethodInfo();
|
||||||
|
result.Context = UpdateNavProvider._Context;
|
||||||
|
var entityInfo = result.Context.EntityMaintenance.GetEntityInfo<T>();
|
||||||
|
Type properyItemType;
|
||||||
|
Expression exp =UtilMethods.GetIncludeExpression(navMemberName, entityInfo, out properyItemType);
|
||||||
|
var method = this.GetType().GetMyMethod("Include", 2)
|
||||||
|
.MakeGenericMethod(properyItemType);
|
||||||
|
var obj = method.Invoke(this, new object[] { exp, updateNavOptions });
|
||||||
|
result.MethodInfos = obj;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public class UpdateNavTask<Root, T> where T : class, new() where Root : class, new()
|
public class UpdateNavTask<Root, T> where T : class, new() where Root : class, new()
|
||||||
{
|
{
|
||||||
|
@@ -0,0 +1,52 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class UpdateNavMethodInfo
|
||||||
|
{
|
||||||
|
internal object MethodInfos { get; set; }
|
||||||
|
internal SqlSugarProvider Context { get; set; }
|
||||||
|
|
||||||
|
public UpdateNavMethodInfo IncludeByNameString(string navMemberName, UpdateNavOptions updateNavOptions = null)
|
||||||
|
{
|
||||||
|
var type = MethodInfos.GetType().GetGenericArguments()[0];
|
||||||
|
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(type);
|
||||||
|
Type properyItemType;
|
||||||
|
Expression exp = UtilMethods.GetIncludeExpression(navMemberName, entityInfo, out properyItemType);
|
||||||
|
var method = this.GetType().GetMyMethod("Include", 2)
|
||||||
|
.MakeGenericMethod(properyItemType);
|
||||||
|
var obj = method.Invoke(this, new object[] { exp, updateNavOptions });
|
||||||
|
this.MethodInfos = obj;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public UpdateNavMethodInfo ThenIncludeByNameString(string IncludeByNameString, UpdateNavOptions updateNavOptions = null)
|
||||||
|
{
|
||||||
|
var type = MethodInfos.GetType().GetGenericArguments()[0];
|
||||||
|
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(type);
|
||||||
|
Type properyItemType;
|
||||||
|
Expression exp = UtilMethods.GetIncludeExpression(navMemberName, entityInfo, out properyItemType);
|
||||||
|
var method = this.GetType().GetMyMethod("ThenInclude", 2)
|
||||||
|
.MakeGenericMethod(properyItemType);
|
||||||
|
var obj = method.Invoke(this, 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -18,7 +18,17 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public class UtilMethods
|
public class UtilMethods
|
||||||
{
|
{
|
||||||
|
internal static Expression GetIncludeExpression(string navMemberName, EntityInfo entityInfo, out Type properyItemType)
|
||||||
|
{
|
||||||
|
var navInfo = entityInfo.Columns.Where(it => it.Navigat != null && it.PropertyName.EqualCase(navMemberName)).FirstOrDefault();
|
||||||
|
var properyType = navInfo.PropertyInfo.PropertyType;
|
||||||
|
properyItemType = properyType;
|
||||||
|
if (properyType.FullName.IsCollectionsList())
|
||||||
|
{
|
||||||
|
properyItemType = properyType.GetGenericArguments()[0];
|
||||||
|
}
|
||||||
|
return ExpressionBuilderHelper.CreateExpressionSelectField(entityInfo.Type, navInfo.PropertyName, properyType);
|
||||||
|
}
|
||||||
public static string RemoveEqualOne(string value)
|
public static string RemoveEqualOne(string value)
|
||||||
{
|
{
|
||||||
value = value.TrimEnd(' ').TrimEnd('1').TrimEnd('=');
|
value = value.TrimEnd(' ').TrimEnd('1').TrimEnd('=');
|
||||||
|
Reference in New Issue
Block a user