From 4d34b46746dafb4894309e5c847f54b761b40ded Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Fri, 9 Jun 2023 12:21:45 +0800 Subject: [PATCH] Update Navigate.Dynmaic --- .../Abstract/QueryableProvider/NavigatManager.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs index 599d23968..c91d9fd37 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs @@ -481,18 +481,22 @@ namespace SqlSugar return; } var navEntity = args[0]; - this.Context.InitMappingInfo(navEntity); - var navEntityInfo = this.Context.EntityMaintenance.GetEntityInfo(navEntity); + + var childDb = this.Context; + childDb = GetCrossDatabase(childDb, navEntity); + + childDb.InitMappingInfo(navEntity); + var navEntityInfo = childDb.EntityMaintenance.GetEntityInfo(navEntity); var sqlObj = GetWhereSql(navObjectNameColumnInfo.Navigat.Name); Check.ExceptionEasy(sqlObj.MappingExpressions.IsNullOrEmpty(), $"{expression} error,dynamic need MappingField ,Demo: Includes(it => it.Books.MappingField(z=>z.studenId,()=>it.StudentId).ToList())", $"{expression} 解析出错,自定义映射需要 MappingField ,例子: Includes(it => it.Books.MappingField(z=>z.studenId,()=>it.StudentId).ToList())"); if (list.Any() && navObjectNamePropety.GetValue(list.First()) == null) { MappingFieldsHelper helper = new MappingFieldsHelper(); - helper.Context = this.Context; + helper.Context = childDb; helper.NavEntity = navEntityInfo; - helper.RootEntity = this.Context.EntityMaintenance.GetEntityInfo(); + helper.RootEntity = childDb.EntityMaintenance.GetEntityInfo(); var whereSql = helper.GetMppingSql(list, sqlObj.MappingExpressions); - var navList = selector(this.Context.Queryable().AS(navEntityInfo.DbTableName).AddParameters(sqlObj.Parameters).Where(whereSql,true).WhereIF(sqlObj.WhereString.HasValue(), sqlObj.WhereString).Select(sqlObj.SelectString).OrderByIF(sqlObj.OrderByString.HasValue(), sqlObj.OrderByString)); + var navList = selector(childDb.Queryable().AS(navEntityInfo.DbTableName).AddParameters(sqlObj.Parameters).Where(whereSql,true).WhereIF(sqlObj.WhereString.HasValue(), sqlObj.WhereString).Select(sqlObj.SelectString).OrderByIF(sqlObj.OrderByString.HasValue(), sqlObj.OrderByString)); if (navList.HasValue()) { foreach (var item in list)