I don't think it is a good practice to use the AddDetail method while loading the Master entity's state
You are right that usage of the AddDetail
method is not a good idea.
I don't know how to load the Details which are part of the state of the Master entity.
How do you load other properties of your Master
entity?
There are a lot of available options I mentioned answering another question (How to retrieve Domain Object from Repositories) :
- ORMs can map private fields (e.g. NHibernate, EntityFramework).
- Reflection can be used to access private fields.
- The collection can be passed via public constructor that is used to construct an entity. I would avoid using public setters for collections.
- 3-rd part frameworks can be useful sometimes (e.g. AutoMapper)
Since collection of Detail
entities is simply a Master
's property I would use an approach that is used for loading other properties.