I am new to Repository pattern.
When I am managing the CRUD
operations of several entities (like: customers, orders etc) then its fine. I am making an i
How should I manage Generic Repository Pattern when the works of different entities are pretty much different?
This is the core problem with Generic Repository pattern; that is why it is considered an anti-pattern.
I read this here:
No matter what clever mechanism I tried, I always ended up at the same problem: a repository is a part of the domain being modeled, and that domain is not generic. Not every entity can be deleted, not every entity can be added, not every entity has a repository. Queries vary wildly; the repository API becomes as unique as the entity itself.
Why generic repository is anti-pattern?
GetById()
, identifier types may be different.I suggest you read these (1, 2, 3, 4, 5) articles explaining why generic repository is an anit-pattern.
Better approach is:
In any case, do not expose generic repository to calling code. Also, do not expose IQueryable
from concrete repositories.