mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-05 17:37:58 +08:00
UpdateNav.IncludeByNameString
This commit is contained in:
parent
d82c23764a
commit
69779793d3
@ -66,8 +66,9 @@ namespace SqlSugar
|
||||
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)
|
||||
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;
|
||||
|
@ -15,24 +15,26 @@ namespace SqlSugar
|
||||
public UpdateNavMethodInfo IncludeByNameString(string navMemberName, UpdateNavOptions updateNavOptions = null)
|
||||
{
|
||||
var type = MethodInfos.GetType().GetGenericArguments()[0];
|
||||
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(type);
|
||||
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(type);
|
||||
Type properyItemType;
|
||||
Expression exp = UtilMethods.GetIncludeExpression(navMemberName, entityInfo, out properyItemType);
|
||||
var method = this.GetType().GetMyMethod("Include", 2)
|
||||
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, new object[] { exp, updateNavOptions });
|
||||
var obj = method.Invoke(this.MethodInfos, new object[] { exp, updateNavOptions });
|
||||
this.MethodInfos = obj;
|
||||
return this;
|
||||
}
|
||||
public UpdateNavMethodInfo ThenIncludeByNameString(string IncludeByNameString, UpdateNavOptions updateNavOptions = null)
|
||||
public UpdateNavMethodInfo ThenIncludeByNameString(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("ThenInclude", 2)
|
||||
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, new object[] { exp, updateNavOptions });
|
||||
var obj = method.Invoke(this.MethodInfos, new object[] { exp, updateNavOptions });
|
||||
this.MethodInfos = obj;
|
||||
return this;
|
||||
}
|
||||
|
@ -32,6 +32,14 @@ namespace SqlSugar
|
||||
it.GetParameters().Length == argCount&&
|
||||
it.GetParameters().First().ParameterType==parameterType);
|
||||
}
|
||||
public static MethodInfo GetMyMethod(this Type type, string name, int argCount, bool isList)
|
||||
{
|
||||
var methods= type.GetMethods().Where(it => it.Name == name).Where(it =>
|
||||
it.GetParameters().Length == argCount&&
|
||||
it.GetParameters()[0].ToString().Contains("List`") == isList).ToList();
|
||||
return methods.First();
|
||||
}
|
||||
|
||||
public static MethodInfo GetMyMethod(this Type type, string name, int argCount, Type parameterType,Type parameterType2)
|
||||
{
|
||||
return type.GetMethods().Where(it=>it.Name == name).FirstOrDefault(it =>
|
||||
|
@ -18,7 +18,7 @@ namespace SqlSugar
|
||||
{
|
||||
public class UtilMethods
|
||||
{
|
||||
internal static Expression GetIncludeExpression(string navMemberName, EntityInfo entityInfo, out Type properyItemType)
|
||||
internal static Expression GetIncludeExpression(string navMemberName, EntityInfo entityInfo, out Type properyItemType,out bool isList)
|
||||
{
|
||||
var navInfo = entityInfo.Columns.Where(it => it.Navigat != null && it.PropertyName.EqualCase(navMemberName)).FirstOrDefault();
|
||||
var properyType = navInfo.PropertyInfo.PropertyType;
|
||||
@ -26,6 +26,11 @@ namespace SqlSugar
|
||||
if (properyType.FullName.IsCollectionsList())
|
||||
{
|
||||
properyItemType = properyType.GetGenericArguments()[0];
|
||||
isList = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isList = false;
|
||||
}
|
||||
return ExpressionBuilderHelper.CreateExpressionSelectField(entityInfo.Type, navInfo.PropertyName, properyType);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user