Hi,
Using 3.1 Adapter gen code, I am trying to populate an object graph from the Adventure Works Database (not 2008 version) with the following code:
public EntityCollection GetAllCustomers()
{
EntityCollection customers = new EntityCollection(new ContactEntityFactory());
IPrefetchPath2 prefetchPathCustomers = new PrefetchPath2((int)EntityType.ContactEntity);
IPrefetchPathElement2 preFetch1 = prefetchPathCustomers.Add(ContactEntity.PrefetchPathIndividuals);
IPrefetchPathElement2 preFetch2 = prefetchPathCustomers.Add(ContactEntity.PrefetchPathIndividuals);
preFetch1.SubPath.Add(IndividualEntity.PrefetchPathCustomer)
.SubPath.Add(CustomerEntity.PrefetchPathCustomerAddresses)
.SubPath.Add(CustomerAddressEntity.PrefetchPathAddress);
preFetch2.SubPath.Add(IndividualEntity.PrefetchPathCustomer)
.SubPath.Add(CustomerEntity.PrefetchPathCustomerAddresses)
.SubPath.Add(CustomerAddressEntity.PrefetchPathAddressType);
using (DataAccessAdapter adapter = AdaptorFactory.GetNewAdaptor(true))
{
adapter.FetchEntityCollection(customers, null, prefetchPathCustomers);
}
return customers;
}
The difficulty is that AddressType is a parent table of CustomerAddress and not Address. So I could not continue the 1st sub-path branch from Address to AddressType.
The code above failed the following error message:
The PrefetchPathElement you to tried to add is already added to this PrefetchPath.
Parameter name: elementToAdd
Is there a way to achieve what I want to achieve? The idea is to load the Contacts and then a whole bunch of other information about the Contacts e.g. address, address type.
Cheers