From 3bd8a1c8ece4d4ccdf69643084ebead0da23c72d Mon Sep 17 00:00:00 2001 From: Jason Webb <46631010+JasonMWebb@users.noreply.github.com> Date: Thu, 30 Jul 2020 12:02:39 -0400 Subject: [PATCH] Updated integration tests and NuGet packages. --- .../EFCoreRepositoryIntegrationTests.cs | 26 ++++++++++++++++ .../EFCoreRepository.cs | 31 +++++++++++++------ .../RCommon.ObjectAccess.EFCore.csproj | 2 +- .../RCommon.ObjectAccess.NHibernate.csproj | 2 +- RCommon/RCommon.csproj | 2 +- 5 files changed, 50 insertions(+), 13 deletions(-) diff --git a/RCommon.ObjectAccess.EFCore.Tests/EFCoreRepositoryIntegrationTests.cs b/RCommon.ObjectAccess.EFCore.Tests/EFCoreRepositoryIntegrationTests.cs index c737af0f..fcde5f68 100644 --- a/RCommon.ObjectAccess.EFCore.Tests/EFCoreRepositoryIntegrationTests.cs +++ b/RCommon.ObjectAccess.EFCore.Tests/EFCoreRepositoryIntegrationTests.cs @@ -8,6 +8,7 @@ using System; using System.Diagnostics; using System.Reflection; +using System.Threading.Tasks; namespace RCommon.ObjectAccess.EFCore.Tests { @@ -435,5 +436,30 @@ public void Can_eager_load_repository_and_query() Assert.IsTrue(savedCustomer.Orders.Count == 10); } + [Test] + public async Task Can_eager_load_repository_and_query_async() + { + _context = new TestDbContext(this.Configuration); + var testData = new EFTestData(_context); + var testDataActions = new EFTestDataActions(testData); + var customer = testDataActions.CreateCustomer(); + for (int i = 0; i < 10; i++) + { + testDataActions.CreateOrderForCustomer(customer); + } + + var repo = this.ServiceProvider.GetService>(); + repo.EagerlyWith(x => x.Orders); + repo.DataStoreName = "TestDbContext"; + //var repo = this.ServiceProvider.GetService>(); + var savedCustomer = await repo + .FindSingleOrDefaultAsync(x => x.CustomerId == customer.CustomerId); + + Assert.IsNotNull(savedCustomer); + Assert.IsTrue(savedCustomer.CustomerId == customer.CustomerId); + Assert.IsTrue(savedCustomer.Orders != null); + Assert.IsTrue(savedCustomer.Orders.Count == 10); + } + } } \ No newline at end of file diff --git a/RCommon.ObjectAccess.EfCore/EFCoreRepository.cs b/RCommon.ObjectAccess.EfCore/EFCoreRepository.cs index 2736849f..91764e29 100644 --- a/RCommon.ObjectAccess.EfCore/EFCoreRepository.cs +++ b/RCommon.ObjectAccess.EfCore/EFCoreRepository.cs @@ -341,22 +341,33 @@ protected override IQueryable RepositoryQuery { get { + IQueryable query; if (ReferenceEquals(this._repositoryQuery, null)) + { + query = this.CreateQuery(); + } + else + { + query = _repositoryQuery; + } + + // Start Eagerloading + + + if (this._includes.Count > 0) { Action action = null; - var query = this.CreateQuery(); - if (this._includes.Count > 0) + if (action == null) { - if (action == null) - { - action = delegate (string m) { - query = query.Include(m); - }; - } - this._includes.ForEach(action); + action = delegate (string m) { + query = query.Include(m); + }; } - this._repositoryQuery = query; + this._includes.ForEach(action); // Build the eagerloaded query + this._includes.Clear(); // clear the eagerloading paths so we don't duplicate efforts if another repository method is called } + this._repositoryQuery = query; + return this._repositoryQuery; } } diff --git a/RCommon.ObjectAccess.EfCore/RCommon.ObjectAccess.EFCore.csproj b/RCommon.ObjectAccess.EfCore/RCommon.ObjectAccess.EFCore.csproj index 6789c580..fde1f87b 100644 --- a/RCommon.ObjectAccess.EfCore/RCommon.ObjectAccess.EFCore.csproj +++ b/RCommon.ObjectAccess.EfCore/RCommon.ObjectAccess.EFCore.csproj @@ -12,7 +12,7 @@ Rcommon, generic repository, .NET Core, Entity Framework Core Repository true GitHub - 1.0.0.16 + 1.0.0.18 diff --git a/RCommon.ObjectAccess.NHibernate/RCommon.ObjectAccess.NHibernate.csproj b/RCommon.ObjectAccess.NHibernate/RCommon.ObjectAccess.NHibernate.csproj index 23a61c36..c9302829 100644 --- a/RCommon.ObjectAccess.NHibernate/RCommon.ObjectAccess.NHibernate.csproj +++ b/RCommon.ObjectAccess.NHibernate/RCommon.ObjectAccess.NHibernate.csproj @@ -13,7 +13,7 @@ GitHub reactor2-icon-darkbg-small.jpg 1.0.0.0 - 1.0.0.10 + 1.0.0.11 diff --git a/RCommon/RCommon.csproj b/RCommon/RCommon.csproj index 4ccff6fa..36fa87a1 100644 --- a/RCommon/RCommon.csproj +++ b/RCommon/RCommon.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 1.0.0.15 + 1.0.0.16 Reactor2 Reactor2 A lightweight application framework used for building applications with data access requirements for one or many data stores and data store types. Simplified unit of work pattern, domain services, application services, and base UI classes.