Reputation: 912
I began working with some many to many relationships in EF code first and found that I don't like having collections on my entities. I would much prefer the many to many relationships be handled in my repository so I can do something like repository.GetUsersForOrganization(organization)
. My main concern is not exposing a collection on my entities and having a few methods on my repositories handle everything concerning the many to many relationships including fetching, adding, and deleting the relationships. I'm pretty much at a loss as to the best way to go about removing the collections and replacing it with the repository based approach. How have other people accomplished this?
Upvotes: 3
Views: 276
Reputation: 364399
If you don't want to have navigation properties for many-to-many relations on your entities you will simply not map those many-to-many relations and you will instead map junction tables for many-to-many relations as separate entities and access them directly in your specialized methods in repository.
Upvotes: 3