Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/find not eagerloading in repository #137

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Src/RCommon.EfCore/Crud/EFCoreRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ public override bool Tracking

public override IEagerLoadableQueryable<TEntity> Include(Expression<Func<TEntity, object>> path)
{
_includableQueryable = RepositoryQuery.Include(path);
_includableQueryable = ObjectContext.Set<TEntity>().Include(path);
return this;
}

public override IEagerLoadableQueryable<TEntity> ThenInclude<TPreviousProperty, TProperty>(Expression<Func<object, TProperty>> path)
{
// TODO: This is likely a bug. The received is incorrect.
_repositoryQuery = _includableQueryable.ThenInclude(path);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Customer>();

// 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<IGraphRepository<Customer>>();
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);
}

}
}
Loading