From c4638b4bbd2ac18da86ddbb5a6f2df2f0cd3ef84 Mon Sep 17 00:00:00 2001 From: Jason Webb Date: Thu, 12 Sep 2024 10:15:04 -0600 Subject: [PATCH 1/2] Updated find method in EFCoreRepository to eagerload using ObjectContext rather than RepositoryQuery since RepositoryQuery is not used in FindAsync(object primarykey) method. --- Src/RCommon.EfCore/Crud/EFCoreRepository.cs | 3 +- .../EFCoreRepositoryIntegrationTests.cs | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Src/RCommon.EfCore/Crud/EFCoreRepository.cs b/Src/RCommon.EfCore/Crud/EFCoreRepository.cs index cec2eca2..ea9b7cb1 100644 --- a/Src/RCommon.EfCore/Crud/EFCoreRepository.cs +++ b/Src/RCommon.EfCore/Crud/EFCoreRepository.cs @@ -90,12 +90,13 @@ public override bool Tracking public override IEagerLoadableQueryable Include(Expression> path) { - _includableQueryable = RepositoryQuery.Include(path); + _includableQueryable = ObjectContext.Set().Include(path); return this; } public override IEagerLoadableQueryable ThenInclude(Expression> path) { + // TODO: This is likely a bug. The received is incorrect. _repositoryQuery = _includableQueryable.ThenInclude(path); return this; } diff --git a/Tests/RCommon.Persistence.EFCore.Tests/EFCoreRepositoryIntegrationTests.cs b/Tests/RCommon.Persistence.EFCore.Tests/EFCoreRepositoryIntegrationTests.cs index 37a725c5..3140d407 100644 --- a/Tests/RCommon.Persistence.EFCore.Tests/EFCoreRepositoryIntegrationTests.cs +++ b/Tests/RCommon.Persistence.EFCore.Tests/EFCoreRepositoryIntegrationTests.cs @@ -748,5 +748,34 @@ public async Task Can_Eager_Load_Repository_And_Query_Async() Assert.That(savedCustomer.Orders.Count == 10); } + [Test] + public async Task Can_Eager_Load_Repository_And_Find_Async() + { + var testData = new List(); + + // Generate Test Data + var repo = new TestRepository(this.ServiceProvider); + repo.PersistSeedData(testData); + + var customer = TestDataActions.CreateCustomerStub(); + for (int i = 0; i < 10; i++) + { + var order = TestDataActions.CreateOrderStub(x => x.Customer = customer); + customer.Orders.Add(order); + testData.Add(customer); + } + repo.PersistSeedData(testData); + + var customerRepo = this.ServiceProvider.GetService>(); + customerRepo.Include(x => x.Orders); + var savedCustomer = await customerRepo + .FindAsync(customer.Id); + + Assert.That(savedCustomer != null); + Assert.That(savedCustomer.Id == customer.Id); + Assert.That(savedCustomer.Orders != null); + Assert.That(savedCustomer.Orders.Count == 10); + } + } } From 3def0f81ab6075ca4c4e37213a675c64937741a5 Mon Sep 17 00:00:00 2001 From: Jason Webb Date: Thu, 12 Sep 2024 10:16:59 -0600 Subject: [PATCH 2/2] Updated build version. --- Build/Build.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Build/Build.cs b/Build/Build.cs index 101185e6..cbde9cd6 100644 --- a/Build/Build.cs +++ b/Build/Build.cs @@ -135,7 +135,7 @@ protected override void OnBuildInitialized() { Log.Information("Generating NuGet packages for projects in solution"); int commitNum = 0; - string NuGetVersionCustom = "2.0.0.884"; + string NuGetVersionCustom = "2.0.0.885"; //if it's not a tagged release - append the commit number to the package version