pfew
It took some real behind-the-scenes refactoring but they now work: prefetch paths in SelfServicing. They did already work for adapter yesterday, including m:n prefetches, filtering, limitation and ordering
Below a complex prefetch path solution: read all employees and in their 'Orders' collection the last Order entity they processed
No other O/R mapper can do this at the moment, and I'm very happy it now works
I paste the selfservicing examples below, adapter has this also of course.
/// <summary>
/// Tests the prefetch path functionality. Loads all employees and per employee the last order object they closed.
/// Similar to FieldCompareSetTestComplex but now with entities.
/// </summary>
[Test]
public void PrefetchPathTestComplex()
{
EmployeeCollection employees = new EmployeeCollection();
IPrefetchPath prefetchPath = new PrefetchPath((int)EntityType.EmployeeEntity);
ISortExpression sorter = new SortExpression();
sorter.Add(SortClauseFactory.Create(OrderFieldIndex.OrderDate, SortOperator.Descending));
prefetchPath.Add(EmployeeEntity.PrefetchPathOrders, 1, null, null, sorter);
employees.GetMulti(null, prefetchPath);
}
M:N relations:
/// <summary>
/// Tests the prefetch path functionality. Simple test: load one customer and all its employees (m:n)
/// </summary>
[Test]
public void PrefetchPathTestSimpleSingleEntityManyToMany()
{
IPrefetchPath prefetchPath = new PrefetchPath((int)EntityType.CustomerEntity);
prefetchPath.Add(CustomerEntity.PrefetchPathEmployees);
CustomerEntity customer = new CustomerEntity("BLONP", prefetchPath);
Assert.AreEqual(7, customer.Employees.Count);
}
multiple levels: Customers -> Orders -> OrderDetails.
just 3 queries run for this
/// <summary>
/// Tests the prefetch path functionality. Simple test: load all customers and all their orders.
/// </summary>
[Test]
public void PrefetchPathTestSimple()
{
CustomerCollection customers = new CustomerCollection();
IPrefetchPath prefetchPath = new PrefetchPath((int)EntityType.CustomerEntity);
prefetchPath.Add(CustomerEntity.PrefetchPathOrders).SubPath.Add(OrderEntity.PrefetchPathOrderDetails);
customers.GetMulti(null, prefetchPath);
}
single entity + prefetch path:
/// <summary>
/// Tests the prefetch path functionality. Simple test: load one customer and all its employees (m:n)
/// </summary>
[Test]
public void PrefetchPathTestSimpleSingleEntityManyToMany()
{
IPrefetchPath prefetchPath = new PrefetchPath((int)EntityType.CustomerEntity);
prefetchPath.Add(CustomerEntity.PrefetchPathEmployees);
CustomerEntity customer = new CustomerEntity("BLONP", prefetchPath);
Assert.AreEqual(7, customer.Employees.Count);
}
Unique constraint fetch with prefetch path:
/// <summary>
/// Tests the prefetch path functionality. Simple test: load one customer and all its orders, based on the customer's Unique constraint.
/// </summary>
[Test]
public void PrefetchPathTestSimpleSingleEntityUC()
{
CustomerEntity customer = new CustomerEntity();
IPrefetchPath prefetchPath = new PrefetchPath((int)EntityType.CustomerEntity);
prefetchPath.Add(CustomerEntity.PrefetchPathOrders).SubPath.Add(OrderEntity.PrefetchPathOrderDetails);
customer.FetchUsingUCCompanyName("Blauer See Delikatessen", prefetchPath);
Assert.AreEqual(7, customer.Orders.Count);
}