ChicagoKiwi wrote:
Working with the following simplified model:
Customers have Contacts (1:n)
Customers belong to Projects (m:n)
Projects have Resources (1:n)
On the addition (or change) of a Customer to a Project I want to add all the Customer's Contacts to the Project as Resources (it's not really this simple but this demonstrates what I'm trying to solve).
So I figured that OnCustomerChanged of the ProjectCustomer entity (the m:n resolver) I'll fetch the Customer Entity, the Project Entity, the Contacts Collection for the Customer, and the Resources Collection for the Project. Then I'll add the Contacts as Resources checking for dupes.
So:
1. Is OnCustomerChanged even the right place to be doing this?
I assume you're using adapter, so you'll need to supply an adapter object anyway, I'd go for a call to a method which does the fetching at the spot where you set the Project's customer, i.e.: in a routine which assigns a customer to a project and handles this fetching as well.
- How can I fetch the project, etc. in the most efficient way (I would think that I'd construct a PreFetch path with the Project, Customer, Contacts, and Resources and then Fetch the ProjectCustomer but that's going to ditch my changed customer, right)?
Fetch with a prefetch path:
Project, ProjectCustomer, Customer, Contacts and resources. The m:n relation is readonly, you need the intermediate entities loaded as well.
- If I'm using a UnitofWork how am I going to add these changes to that?
The UnitOfWork is a collector for actions performed on entities and offers you a way to postpone all these actions till you call Commit. So every time you have to perform an action on a set of entities (no selects, just save/delete) you add the action to the UnitOfWork.