Skip to content

Commit

Permalink
Merging with main.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmwebb-lv committed Oct 18, 2024
2 parents 924087b + 4aca138 commit 1c3189b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Src/RCommon.EfCore/Crud/EFCoreRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,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);
}

}
}

0 comments on commit 1c3189b

Please sign in to comment.