Hi. I have been trying to get prefetch to work with adapter. So far so good - until I got to M:N relations. I saw the documentation about it that states:
M:N related entities
Prefetch Paths can also be used to fetch m:n related entities, they work the same as other related entities. There is one caveat: the intermediate entities are not fetched with an m:n relation Prefetch Path. For example, if you fetch a set of Customer entities and also their m:n related Employee entities, the intermediate entity, Order, is not fetched. If you specify, via another PrefetchPathElement2, to fetch the Order entities as well, and via a SubPath also their related Employee entities, these Employee entities are not the same objects as located in the Employees collection of every Customer entity you fetched.
but I don't totally understand. I have a Windows c# application with this in the form load:
public EntityCollection customers;
customers = new EntityCollection(new CustomersEntityFactory());
IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.CustomersEntity);
prefetchPath.Add(CustomersEntity.PrefetchPathOrders).SubPath.Add(OrdersEntity.PrefetchPathEmployees);
IRelationPredicateBucket filter = null;
DataAccessAdapter adapter = new DataAccessAdapter();
adapter.FetchEntityCollection(customers, filter, prefetchPath);
I thought this would fill all customers, all orders and all employee objects. I then would be able to, without making any more database calls, look up an employee name based on a customer's order. So I have a button on the form that has this code:
CustomersEntity selectedCustomer = (CustomersEntity)customers[
customers.Find( new EntityPropertyDescriptor2(
EntityFieldFactory.Create(CustomersFieldIndex.CustomerID),
typeof(CustomersEntity), false),
"CHOPS" )];
gridOrders.DataSource = selectedCustomer.Employees;
I would expect the grid to be filled with all the employees involved in selectedCustomer's orders but the grid is empty. I also did the following:
gridOrders.DataSource = selectedCustomer.Orders;
and I can see the orders for CHOPS in the grid. However, when I click on the plus sign to see the related links, all I see are links to Products and Order Details. I would like to see Employees also. Could you explain how to do this? My goal is to at the program startup, load all customers meeting a certain criteria (I took the criteria out for the example), load their related orders, and load the employees associated with those orders. I would then like to manipulate the data for as long as needed until I am ready update to the server. Is this possible? If you like I have the sample project where I have tried this and can email it if needed. Thanks very much for your help.