Last night I was thinking about a new type of problem about O/R Mapper. ("With Great Power Comes Great Responsibility" )
Said that I have a project with 3 entities.
Customer --> Address
Customer --> Phones
Said that I have a business class (BcCustAddr) that fetch/persist a graph composed by Customers and Address.
Said that I have another business class (BcPhones) that add phones to the customer, but olny after some particular validation.
Now My Gui layer can fetch a group of Customers/Address through BcCustAddr.
After that, the Gui layer can create a new Phones entity, and inject this entity in to the object graph.
Now the Gui can use BcCustAddr to persist the changes, and even the injected phones will be written down in the DB (bypassing the validation imposed by BcPhones).
How do you handle this type of problem?
I'm thinking about the following approach:
*) My business class know the data that will be loaded, because of a PrefetchPath harcoded in de businessClass
*) so my BC can explore the prefetchpath and create a list of the admitted EntityType
*) After that, during Persist/Validation, the BC can explore the entity graph, and check that all the entities are of the correct type
This is a simplistic approach, and will fail if a particular type of entity can exist in different branch of the prefetch path.
I'll need to think about some better check routine...
What do you think about this approach?
Thanks, Max