Quantcast
Channel: URF - Unit of Work & (extensible/generic) Repositories Framework
Viewing all articles
Browse latest Browse all 1539

Commented Unassigned: Child rows not being retrieve. Help! [1233]

$
0
0
When I run the code below the correct record is found (at line A) and assigned to the variable x. But on inspecting the variable x, during debugging, __all child records__ ie "Orders" and "CustomerDemographics", have count of Zero.

Why is this this happening! Help!


```
using (IDataContextAsync myDbContext = new NorthwindContext())
{
using (var uow = new UnitOfWork(myDbContext))
{
var orderRepo = new Repository<Customer>(myDbContext, uow);

var x = orderRepo.Find("ALFKI"); // <--- line A
var x2 = x.Orders;
var x3 = x2.SelectMany(o => o.OrderDetails);
var x4 = x3.Select(o => o.Quantity * o.UnitPrice);
var x5 = x4.Sum();
}
}
```

I am using v3.3. and EF6.
Comments: You need some include statements so that the related entities are loaded. Try using `QueryFluent`: ``` using (IDataContextAsync myDbContext = new NorthwindContext()) using (IUnitOfWorkAsync uow = new UnitOfWork(myDbContext, repositoryProvider)) { var orderRepo = new Repository<Customer>(myDbContext, uow); Customer x = new QueryFluent<Customer>(orderRepo, c => c.CustomerID == "ALFKI") .Include(c => c.Orders) .Include(c => c.Orders.Select(o => o.OrderDetails)) .Select() .First(); // <--- line A var x2 = x.Orders; Assert.AreEqual(6, x2.Count); var x3 = x2.SelectMany(o => o.OrderDetails); Assert.AreEqual(12, x3.Count()); var x4 = x3.Select(o => o.Quantity * o.UnitPrice); var x5 = x4.Sum(); Assert.AreEqual(4596.2m, x5); } ```

Viewing all articles
Browse latest Browse all 1539

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>