views:

206

answers:

1

Hi I looked at lot of examples online using Repository Pattern with EF. But none of them really talked about working with Related Entities.

Like say User can have multiple addresses.

IUserRepository
User CreateUser();
void UpdateUser();

Now if I were to add a Address to the User should, should it be on the Repository? OR on the User instance

I feel repository pattern shud be used for CRUD and Get Operations on the entity. But when it comes to working with related entities, they should really be defined on the entity[for the most part]

Like in this scenario, address is useless without a user, shouldnt it be on the entity?

any thoughts?

+1  A: 

This isn't really an EF question; it's more of a Repository pattern question. Pick up a DDD book and read up on the concept of aggregate roots. If an address is "useless without a user," then it probably should not have CRUD methods on a repository, as you say. But the aggregate root concept makes this much more formal.

Craig Stuntz