mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-04 23:39:31 +08:00
Special integration usage includes(x=> x.xx.tolist ())
This commit is contained in:
parent
6299757220
commit
f9d484959e
@ -93,21 +93,9 @@ namespace SqlSugar
|
||||
private InsertNavProvider<Root, TChild> _ThenInclude<TChild>(Expression<Func<T, List<TChild>>> expression) where TChild : class, new()
|
||||
{
|
||||
var name = ExpressionTool.GetMemberName(expression);
|
||||
if (expression is LambdaExpression lambda)
|
||||
if (name == null)
|
||||
{
|
||||
if (lambda.Body is MethodCallExpression method)
|
||||
{
|
||||
if (method.Method.Name == "ToList")
|
||||
{
|
||||
if (method.Arguments.FirstOrDefault() is { } arg)
|
||||
{
|
||||
if (arg is MemberExpression member)
|
||||
{
|
||||
name = member.Member.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
name =ExpressionTool.GetMemberNameByMethod(expression, name);
|
||||
}
|
||||
var isRoot = false;
|
||||
if (this._ParentEntity == null)
|
||||
@ -137,7 +125,7 @@ namespace SqlSugar
|
||||
InitParentList();
|
||||
InsertManyToMany<TChild>(name, nav);
|
||||
}
|
||||
AddContextInfo(name,isRoot);
|
||||
AddContextInfo(name, isRoot);
|
||||
return GetResult<TChild>();
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
@ -137,6 +138,10 @@ namespace SqlSugar
|
||||
}
|
||||
children.AddRange(childs);
|
||||
}
|
||||
else if (childs == null && parentNavigateProperty.PropertyInfo.GetValue(item) is IList ilist && ilist != null && ilist.Count > 0)
|
||||
{
|
||||
childs = GetIChildsBylList(children, thisFkColumn, parentValue, ilist);
|
||||
}
|
||||
ids.Add(parentValue);
|
||||
if (_Options?.OneToManyNoDeleteNull == true && childs == null)
|
||||
{
|
||||
@ -194,6 +199,16 @@ namespace SqlSugar
|
||||
_NavigateType = null;
|
||||
SetNewParent<TChild>(thisEntity, thisPkColumn);
|
||||
}
|
||||
private static List<TChild> GetIChildsBylList<TChild>(List<TChild> children, EntityColumnInfo thisFkColumn, object parentValue, IList ilist) where TChild : class, new()
|
||||
{
|
||||
List<TChild> childs = ilist.Cast<TChild>().ToList();
|
||||
foreach (var child in childs)
|
||||
{
|
||||
thisFkColumn.PropertyInfo.SetValue(child, parentValue, null);
|
||||
}
|
||||
children.AddRange(childs);
|
||||
return childs;
|
||||
}
|
||||
|
||||
private static bool ParentIsPk(EntityColumnInfo parentNavigateProperty)
|
||||
{
|
||||
|
@ -97,6 +97,10 @@ namespace SqlSugar
|
||||
IsFirst = isRoot && this._ParentList == null;
|
||||
InitParentList();
|
||||
var name = ExpressionTool.GetMemberName(expression);
|
||||
if (name == null)
|
||||
{
|
||||
name = ExpressionTool.GetMemberNameByMethod(expression, name);
|
||||
}
|
||||
var nav = this._ParentEntity.Columns.FirstOrDefault(x => x.PropertyName == name);
|
||||
if (nav.Navigat == null)
|
||||
{
|
||||
|
@ -10,6 +10,29 @@ namespace SqlSugar
|
||||
{
|
||||
public class ExpressionTool
|
||||
{
|
||||
|
||||
public static string GetMemberNameByMethod(Expression expression, string name)
|
||||
{
|
||||
if (expression is LambdaExpression lambda)
|
||||
{
|
||||
if (lambda.Body is MethodCallExpression method)
|
||||
{
|
||||
if (method.Method.Name == "ToList")
|
||||
{
|
||||
if (method.Arguments.FirstOrDefault() is { } arg)
|
||||
{
|
||||
if (arg is MemberExpression member)
|
||||
{
|
||||
name = member.Member.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
internal static string ResolveMemberValue(ExpressionContext context, Expression item, string value)
|
||||
{
|
||||
if (item is MemberExpression member)
|
||||
|
@ -2,7 +2,7 @@
|
||||
<package >
|
||||
<metadata>
|
||||
<id>SqlSugarCore</id>
|
||||
<version>5.1.4.188-preview03</version>
|
||||
<version>5.1.4.188-preview09</version>
|
||||
<authors>sunkaixuan</authors>
|
||||
<owners>果糖大数据科技</owners>
|
||||
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>
|
||||
|
Loading…
Reference in New Issue
Block a user