From dc4d70b325c9831ed259ccaf19f5e37970903d52 Mon Sep 17 00:00:00 2001 From: 2881099 <2881099@qq.com> Date: Thu, 2 Mar 2023 16:37:22 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8D=203.2.689=20WithTempQuer?= =?UTF-8?q?y=20DTO=20=E6=98=A0=E5=B0=84=E6=9F=A5=E8=AF=A2=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=9B#1441=20#1436=20#1434=20#1433=20#1431=20#1429?= =?UTF-8?q?=20#1427=20#1425=20#1417=20#1413=20#1412=20#1319?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base_entity/AspNetRoleClaims/ids_api.db | Bin 172032 -> 176128 bytes Examples/base_entity/Program.cs | 65 ++++-------------- FreeSql.DbContext/FreeSql.DbContext.xml | 9 --- FreeSql.sln | 19 ++++- FreeSql/Internal/CommonExpression.cs | 3 +- FreeSql/Internal/UtilsExpressionTree.cs | 7 +- 6 files changed, 35 insertions(+), 68 deletions(-) diff --git a/Examples/base_entity/AspNetRoleClaims/ids_api.db b/Examples/base_entity/AspNetRoleClaims/ids_api.db index a45d6fa32d61ff3f08186c00d17d207548783f35..41420d00c24c9da33b258c04905d1aed5ddd03c9 100644 GIT binary patch delta 348 zcmZoTz}4`8Yl5_3J_7@THW0&r^h6zF#{9;FtqF`v^clscvl=k!vvAAs+@Cm6dwa40 zqdgZBL(Sw~#)|qTAvJb!MMcKu{F20^oYbuR%)FA+;t~Tx1WVgF$kj2#RUyRD$;VYe z2_d1RprN3^%cY>8l$oNW;OQ6Q>h2n(;O8Hr;1}xSqXUsj&QD2IQt%6N4085x4AL+% zHPwX56eJd<*5{SrR*;vNi$g2I4XJshx!8?IRbzzRfzyxJFbc2(ov+EurP*$1!?@kh LhUt9rq6Y#1pFmsM delta 77 zcmZp8z}0YoYl5_39s>h|77)XL)I=R)#=ORatqF`v^clsbvl=k!voJ95+@Cm6dwa40 aqdgZB Condition = condition; - } public class JoinTest01 { public int id { get; set; } @@ -382,8 +377,10 @@ namespace base_entity [Column(MapType = typeof(int))] public JoinTest01Enum JoinTest01Enum2 { get; set; } - [JoinCondition("a.parentcode = b.code")] + [Navigate(nameof(parentcode), TempPrimary = nameof(JoinTest01.code))] public JoinTest01 Parent { get; set; } + [Navigate(nameof(JoinTest01.parentcode), TempPrimary = nameof(code))] + public List Childs { get; set; } } public enum JoinTest01Enum { f1, f2, f3 } @@ -572,6 +569,14 @@ namespace base_entity #endregion fsql.UseJsonMap(); + var joinsql1 = fsql.Select() + .Include(a => a.Parent.Parent) + .Where(a => a.Parent.Parent.code == "001") + .Where(a => a.JoinTest01Enum == JoinTest01Enum.f3.ToString()) + .Where(a => object.Equals(a.JoinTest01Enum, JoinTest01Enum.f3)) + .Where(a => new[] { JoinTest01Enum.f2, JoinTest01Enum.f3 }.Contains(a.JoinTest01Enum2)) + .ToSql(); + var atimpl = fsql.CodeFirst.GetTableByEntity(typeof(AsTableLog)) .AsTableImpl; @@ -899,53 +904,7 @@ namespace base_entity }); var sqldel4 = fsql.DeleteDict(diclist).AsTable("table1").ToSql(); - fsql.Aop.ParseExpression += (_, e) => - { - if (e.Expression is MemberExpression memExp == false) return; - ParameterExpression parmExp = null; - var exps = new List(); - exps.Add(memExp); - while (memExp.Expression != null) - { - if (memExp.Expression is MemberExpression parentExp) - { - exps.Add(parentExp); - memExp = parentExp; - if (fsql.CodeFirst.GetTableByEntity(memExp.Type) == null) return; - continue; - } - if (memExp.Expression is ParameterExpression parmExp2) - { - parmExp = parmExp2; - break; - } - return; - } - if (parmExp == null) return; - if (e.Tables == null) return; - var oldTables = e.Tables.ToArray(); - var result = e.FreeParse(e.Expression); - for (var a = oldTables.Length; a < e.Tables.Count; a++) - { - if (string.IsNullOrEmpty(e.Tables[a].NavigateCondition) == false) continue; - var parentTableAlias = e.Tables[a].Alias?.Split(new[] { "__" }, StringSplitOptions.None); - if (parentTableAlias == null || parentTableAlias.Length <= 1) continue; - var parentTable = e.Tables.Where(c => c.Alias == string.Join("__", parentTableAlias.Take(parentTableAlias.Length - 1))).FirstOrDefault(); - if (parentTable == null || parentTable.Table.Properties.TryGetValue(parentTableAlias.Last(), out var navProp) == false) continue; - var joinAttr = navProp.GetCustomAttribute(); - if (joinAttr == null) continue; - e.Tables[a].NavigateCondition = joinAttr.Condition - .Replace("a.", e.Tables[a].Alias + ".") - .Replace("b.", parentTable.Alias + "."); - } - }; - var joinsql1 = fsql.Select() - .Include(a => a.Parent.Parent) - .Where(a => a.Parent.Parent.code == "001") - .Where(a => a.JoinTest01Enum == JoinTest01Enum.f3.ToString()) - .Where(a => object.Equals(a.JoinTest01Enum, JoinTest01Enum.f3)) - .Where(a => new[] { JoinTest01Enum.f2, JoinTest01Enum.f3 }.Contains(a.JoinTest01Enum2)) - .ToSql(); + fsql.Aop.ConfigEntity += (_, e) => diff --git a/FreeSql.DbContext/FreeSql.DbContext.xml b/FreeSql.DbContext/FreeSql.DbContext.xml index 26522f10..537315e2 100644 --- a/FreeSql.DbContext/FreeSql.DbContext.xml +++ b/FreeSql.DbContext/FreeSql.DbContext.xml @@ -800,14 +800,5 @@ - - - 批量注入 Repository,可以参考代码自行调整 - - - - - - diff --git a/FreeSql.sln b/FreeSql.sln index ed7da68e..a15fde80 100644 --- a/FreeSql.sln +++ b/FreeSql.sln @@ -119,6 +119,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Tests.Provider.Cust EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Provider.QuestDb", "Providers\FreeSql.Provider.QuestDb\FreeSql.Provider.QuestDb.csproj", "{8A06B18A-A8BF-4AEA-AFE4-0F573C2DBFEE}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Extensions.AggregateRoot", "Extensions\FreeSql.Extensions.AggregateRoot\FreeSql.Extensions.AggregateRoot.csproj", "{71A6F937-D11B-4AE4-9933-BB6B4D925665}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -705,6 +707,18 @@ Global {8A06B18A-A8BF-4AEA-AFE4-0F573C2DBFEE}.Release|x64.Build.0 = Release|Any CPU {8A06B18A-A8BF-4AEA-AFE4-0F573C2DBFEE}.Release|x86.ActiveCfg = Release|Any CPU {8A06B18A-A8BF-4AEA-AFE4-0F573C2DBFEE}.Release|x86.Build.0 = Release|Any CPU + {71A6F937-D11B-4AE4-9933-BB6B4D925665}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {71A6F937-D11B-4AE4-9933-BB6B4D925665}.Debug|Any CPU.Build.0 = Debug|Any CPU + {71A6F937-D11B-4AE4-9933-BB6B4D925665}.Debug|x64.ActiveCfg = Debug|Any CPU + {71A6F937-D11B-4AE4-9933-BB6B4D925665}.Debug|x64.Build.0 = Debug|Any CPU + {71A6F937-D11B-4AE4-9933-BB6B4D925665}.Debug|x86.ActiveCfg = Debug|Any CPU + {71A6F937-D11B-4AE4-9933-BB6B4D925665}.Debug|x86.Build.0 = Debug|Any CPU + {71A6F937-D11B-4AE4-9933-BB6B4D925665}.Release|Any CPU.ActiveCfg = Release|Any CPU + {71A6F937-D11B-4AE4-9933-BB6B4D925665}.Release|Any CPU.Build.0 = Release|Any CPU + {71A6F937-D11B-4AE4-9933-BB6B4D925665}.Release|x64.ActiveCfg = Release|Any CPU + {71A6F937-D11B-4AE4-9933-BB6B4D925665}.Release|x64.Build.0 = Release|Any CPU + {71A6F937-D11B-4AE4-9933-BB6B4D925665}.Release|x86.ActiveCfg = Release|Any CPU + {71A6F937-D11B-4AE4-9933-BB6B4D925665}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -743,10 +757,11 @@ Global {D4FEE5C1-6805-4B46-B10B-BE5CC942B883} = {2A381C57-2697-427B-9F10-55DA11FD02E4} {ECF7FC70-A7FC-4FC3-9BF7-462EA0A65F9C} = {2A381C57-2697-427B-9F10-55DA11FD02E4} {8A06B18A-A8BF-4AEA-AFE4-0F573C2DBFEE} = {2A381C57-2697-427B-9F10-55DA11FD02E4} + {71A6F937-D11B-4AE4-9933-BB6B4D925665} = {4A92E8A6-9A6D-41A1-9CDA-DE10899648AA} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {089687FD-5D25-40AB-BA8A-A10D1E137F98} - RESX_PrefixTranslations = True RESX_NeutralResourcesLanguage = en-US + RESX_PrefixTranslations = True + SolutionGuid = {089687FD-5D25-40AB-BA8A-A10D1E137F98} EndGlobalSection EndGlobal diff --git a/FreeSql/Internal/CommonExpression.cs b/FreeSql/Internal/CommonExpression.cs index d9f6f586..fd22094b 100644 --- a/FreeSql/Internal/CommonExpression.cs +++ b/FreeSql/Internal/CommonExpression.cs @@ -2514,7 +2514,8 @@ namespace FreeSql.Internal { if (tb == null || dtoProp == null || tb.Parameter == null) return null; var retList = new List(); - LocalMatch(tb.Parameter.Type, tb.Parameter); + var retExp = LocalMatch(tb.Parameter.Type, tb.Parameter); + if (retList.Any() == false) retList.Add(new[] { retExp }); return retList; Expression LocalMatch(Type type, Expression memExp) diff --git a/FreeSql/Internal/UtilsExpressionTree.cs b/FreeSql/Internal/UtilsExpressionTree.cs index cdc50759..564e836e 100644 --- a/FreeSql/Internal/UtilsExpressionTree.cs +++ b/FreeSql/Internal/UtilsExpressionTree.cs @@ -632,7 +632,7 @@ namespace FreeSql.Internal var propTypeIsObservableCollection = propElementType != null && pnv.PropertyType == typeof(ObservableCollection<>).MakeGenericType(propElementType); #region islazy - void LocalManyLazyLoadingCode(PropertyInfo refprop, string cscodeExtLogic1, string cscodeExtLogic2, string lmbdWhere) + void LocalOneToManyLazyLoadingCode(PropertyInfo refprop, string cscodeExtLogic1, string cscodeExtLogic2, string lmbdWhere) { cscode.Append(" private bool __lazy__").Append(pnv.Name).AppendLine(" = false;") .Append(" ").Append(propModification).Append(" override ").Append(propTypeName).Append(" ").Append(pnv.Name).AppendLine(" {"); @@ -768,7 +768,7 @@ namespace FreeSql.Internal nvref.RefType = TableRefType.OneToMany; trytb.AddOrUpdateTableRef(pnv.Name, nvref); } - if (isLazy) LocalManyLazyLoadingCode(null, null, null, lmbdWhere.ToString()); + if (isLazy) LocalOneToManyLazyLoadingCode(null, null, null, lmbdWhere.ToString()); } else { @@ -802,6 +802,7 @@ namespace FreeSql.Internal } if (isLazy) LocalLazyLoadingCode(lmbdWhere.ToString()); } + return; } #endregion @@ -1401,7 +1402,7 @@ namespace FreeSql.Internal } } - if (isLazy) LocalManyLazyLoadingCode(refprop, cscodeExtLogic1, cscodeExtLogic2, lmbdWhere.ToString()); + if (isLazy) LocalOneToManyLazyLoadingCode(refprop, cscodeExtLogic1, cscodeExtLogic2, lmbdWhere.ToString()); } } else