From db5f8a9c13d4b1a4c1a3052f308b34d6b785d14a Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Mon, 1 Aug 2022 16:38:12 +0800 Subject: [PATCH] Update exp to sql --- .../ResolveItems/OneToOneNavgateExpressionN.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpressionN.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpressionN.cs index e37281256..2722fa00b 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpressionN.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpressionN.cs @@ -55,6 +55,14 @@ namespace SqlSugar { var shortName = item.ThisEntityInfo.DbTableName + i; var pkColumn = item.ThisEntityInfo.Columns.FirstOrDefault(it => it.IsPrimarykey); + if (item.Nav.Name2.HasValue()) + { + var nav2NameColumn = item.ThisEntityInfo.Columns.FirstOrDefault(it => it.PropertyName==item.Nav.Name2); + if (nav2NameColumn != null) + { + pkColumn = nav2NameColumn; + } + } var navColum = item.ParentEntityInfo.Columns.FirstOrDefault(it => it.PropertyName == item.Nav.Name); Check.ExceptionEasy(pkColumn == null, $"{item.ThisEntityInfo.EntityName} need PrimayKey", $"使用导航属性{item.ThisEntityInfo.EntityName} 缺少主键"); var on = $" {ToShortName(shortName)}.{queryable.SqlBuilder.GetTranslationColumnName(pkColumn.DbColumnName)}={ToShortName(formInfo.ThisEntityInfo.DbTableName + (i - 1))}.{queryable.SqlBuilder.GetTranslationColumnName(navColum.DbColumnName)}";