diff --git a/Examples/base_entity/Program.cs b/Examples/base_entity/Program.cs index d076fe36..7232a880 100644 --- a/Examples/base_entity/Program.cs +++ b/Examples/base_entity/Program.cs @@ -436,6 +436,46 @@ namespace base_entity Math.PI }); + var usergroupRepository = fsql.GetAggregateRootRepository(); + usergroupRepository.Delete(a => true); + usergroupRepository.Insert(new[]{ + new UserGroup + { + CreateTime = DateTime.Now, + GroupName = "group1", + UpdateTime = DateTime.Now, + Sort = 1, + User1s = new List + { + new User1 { Nickname = "nickname11", Username = "username11", Description = "desc11" }, + new User1 { Nickname = "nickname12", Username = "username12", Description = "desc12" }, + new User1 { Nickname = "nickname13", Username = "username13", Description = "desc13" }, + } + }, + new UserGroup + { + CreateTime = DateTime.Now, + GroupName = "group2", + UpdateTime = DateTime.Now, + Sort = 2, + User1s = new List + { + new User1 { Nickname = "nickname21", Username = "username21", Description = "desc21" }, + new User1 { Nickname = "nickname22", Username = "username22", Description = "desc22" }, + new User1 { Nickname = "nickname23", Username = "username23", Description = "desc23" }, + } + }, + }); + var userRepository = fsql.GetAggregateRootRepository(); + + var testsublist1 = fsql.Select() + .First(a => new + { + a.Id, + list = userRepository.Select.Where(b => b.GroupId == a.Id).ToList(), + list2 = userRepository.Select.Where(b => b.GroupId == a.Id).ToList(b => b.Nickname), + }); + Dictionary dic = new Dictionary(); dic.Add("id", 1); diff --git a/Examples/base_entity/base_entity.csproj b/Examples/base_entity/base_entity.csproj index 2892934a..b29f9191 100644 --- a/Examples/base_entity/base_entity.csproj +++ b/Examples/base_entity/base_entity.csproj @@ -17,6 +17,7 @@ + diff --git a/FreeSql-lite.sln b/FreeSql-lite.sln index a5b72d42..989e5166 100644 --- a/FreeSql-lite.sln +++ b/FreeSql-lite.sln @@ -81,6 +81,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Provider.OracleOled EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "aspnetcore_transaction", "Examples\aspnetcore_transaction\aspnetcore_transaction.csproj", "{28163C3B-B2E6-432D-AAC3-F5F19374BE31}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Extensions.AggregateRoot", "Extensions\FreeSql.Extensions.AggregateRoot\FreeSql.Extensions.AggregateRoot.csproj", "{5C78C4CE-3CDC-49C3-AF34-556567B95F2A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -439,6 +441,18 @@ Global {28163C3B-B2E6-432D-AAC3-F5F19374BE31}.Release|x64.Build.0 = Release|Any CPU {28163C3B-B2E6-432D-AAC3-F5F19374BE31}.Release|x86.ActiveCfg = Release|Any CPU {28163C3B-B2E6-432D-AAC3-F5F19374BE31}.Release|x86.Build.0 = Release|Any CPU + {5C78C4CE-3CDC-49C3-AF34-556567B95F2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5C78C4CE-3CDC-49C3-AF34-556567B95F2A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5C78C4CE-3CDC-49C3-AF34-556567B95F2A}.Debug|x64.ActiveCfg = Debug|Any CPU + {5C78C4CE-3CDC-49C3-AF34-556567B95F2A}.Debug|x64.Build.0 = Debug|Any CPU + {5C78C4CE-3CDC-49C3-AF34-556567B95F2A}.Debug|x86.ActiveCfg = Debug|Any CPU + {5C78C4CE-3CDC-49C3-AF34-556567B95F2A}.Debug|x86.Build.0 = Debug|Any CPU + {5C78C4CE-3CDC-49C3-AF34-556567B95F2A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5C78C4CE-3CDC-49C3-AF34-556567B95F2A}.Release|Any CPU.Build.0 = Release|Any CPU + {5C78C4CE-3CDC-49C3-AF34-556567B95F2A}.Release|x64.ActiveCfg = Release|Any CPU + {5C78C4CE-3CDC-49C3-AF34-556567B95F2A}.Release|x64.Build.0 = Release|Any CPU + {5C78C4CE-3CDC-49C3-AF34-556567B95F2A}.Release|x86.ActiveCfg = Release|Any CPU + {5C78C4CE-3CDC-49C3-AF34-556567B95F2A}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -469,10 +483,11 @@ Global {9D82A683-2950-4E8A-B078-A422ECA6AAA5} = {94C8A78D-AA15-47B2-A348-530CD86BFC1B} {19D2E22A-B000-46B6-AFC8-60BF01A51C9A} = {2A381C57-2697-427B-9F10-55DA11FD02E4} {28163C3B-B2E6-432D-AAC3-F5F19374BE31} = {94C8A78D-AA15-47B2-A348-530CD86BFC1B} + {5C78C4CE-3CDC-49C3-AF34-556567B95F2A} = {4A92E8A6-9A6D-41A1-9CDA-DE10899648AA} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {089687FA-5D21-40AC-BA8A-AA0D1E1H7F98} - RESX_PrefixTranslations = True RESX_NeutralResourcesLanguage = en-US + RESX_PrefixTranslations = True + SolutionGuid = {089687FA-5D21-40AC-BA8A-AA0D1E1H7F98} EndGlobalSection EndGlobal diff --git a/FreeSql/Extensions/FreeSqlGlobalExtensions.cs b/FreeSql/Extensions/FreeSqlGlobalExtensions.cs index 35d5ddd0..ac981c63 100644 --- a/FreeSql/Extensions/FreeSqlGlobalExtensions.cs +++ b/FreeSql/Extensions/FreeSqlGlobalExtensions.cs @@ -22,8 +22,12 @@ public static partial class FreeSqlGlobalExtensions { #if net40 #else - static readonly Lazy _TaskReflectionResultPropertyLazy = new Lazy(() => typeof(Task).GetProperty("Result")); - internal static object GetTaskReflectionResult(this Task task) => _TaskReflectionResultPropertyLazy.Value.GetValue(task, new object[0]); + internal static object GetTaskReflectionResult(this Task task) + { + var propResult = task?.GetType().GetProperty("Result"); + if (propResult != null) return propResult.GetValue(task, new object[0]); + return null; + } #endif #region Type 对象扩展方法