My domain is composed from two classes. The first is Patient. The second is Injection. Person can have many injection instances.
This raises architecture issue regarding some OOD, relational Database design and ORM (specifically EntityFramework):
I want that a Patient will hold list of injections property and that an Injection will hold a Patient property. This looks like a good object oriented design.
This design (using EntityFramework code first), will map to two tables: Patients table, and Injections table. The Injections table will have a foreign key to a row in Patients table.
So far so good.
Now, lets assume a database case as described above, with 1 patient which has 100,000 injections.
When I ask DbContext for this patient it will retrive the patient data and the list of Injections will load only by demand.
This looks like a potential problem. I'm saying to any potential user of Patient - "hey, you have a list of injections, use them! Only do - myPatient.Injections and they will magically appear".
However, by exposing this property I am potentially enabling a user of patient to run a very heavy query which may not even be an application need.
A possible solution is to remove the list of Injections from the patient class. Regarding the database, the mapping will remain the same, and in order to query injections of patient I will use a concrete service. But now I have a Patient class that doesn't represent my domain in a good way.
Another possible solution is to map each object returned from EF context to another shallow object. I will map only what i need, and wont expose unneeded data to the user. This approach will cause duplication and the maintaining of mapping between classes.
What do you think about this issue?
Share your knowledege :)