Skip to content

Commit

Permalink
Updated integration tests and NuGet packages.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMWebb committed Jul 30, 2020
1 parent b792fcc commit 3bd8a1c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System;
using System.Diagnostics;
using System.Reflection;
using System.Threading.Tasks;

namespace RCommon.ObjectAccess.EFCore.Tests
{
Expand Down Expand Up @@ -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<IEagerFetchingRepository<Customer>>();
repo.EagerlyWith(x => x.Orders);
repo.DataStoreName = "TestDbContext";
//var repo = this.ServiceProvider.GetService<IEFCoreRepository<Customer>>();
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);
}

}
}
31 changes: 21 additions & 10 deletions RCommon.ObjectAccess.EfCore/EFCoreRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,22 +341,33 @@ protected override IQueryable<TEntity> RepositoryQuery
{
get
{
IQueryable<TEntity> query;
if (ReferenceEquals(this._repositoryQuery, null))
{
query = this.CreateQuery();
}
else
{
query = _repositoryQuery;
}

// Start Eagerloading


if (this._includes.Count > 0)
{
Action<string> 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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageTags>Rcommon, generic repository, .NET Core, Entity Framework Core Repository</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<RepositoryType>GitHub</RepositoryType>
<Version>1.0.0.16</Version>
<Version>1.0.0.18</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<RepositoryType>GitHub</RepositoryType>
<PackageIcon>reactor2-icon-darkbg-small.jpg</PackageIcon>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Version>1.0.0.10</Version>
<Version>1.0.0.11</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion RCommon/RCommon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>1.0.0.15</Version>
<Version>1.0.0.16</Version>
<Authors>Reactor2</Authors>
<Company>Reactor2</Company>
<Description>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.</Description>
Expand Down

0 comments on commit 3bd8a1c

Please sign in to comment.