I have read a lot about Unit of Work and Repositories patterns. What I have never seen is how would I retrieve data. UoW does not make sense for Select statements.

I will use asp.net MVC with n-tier architecture and this point I never see in any tutorial or article:

Where and how do I call SELECT statements, with/without INNER JOINs, using these patterns? Calling directly DataContext from Service Layer?

有帮助吗?

解决方案

Unit of Work is for updating the model. Indeed for querying you don't need it. When using the Repository Pattern everything db related (selects, joins etc) is part of the repository implementation.

The repository consumer, for example the Controller, takes a dependency on the repository interface (an abstraction) while the concrete repository is injected by the DI Container. The consumer never sees the db or things from it, it just sees the repository methods which should return objects the controller needs and understands (even if you return an ROM entity, the controller doesn't know it's an entity).

One important thing is to understand that the repository interface defines the WHAT not the HOW. The implementation deals with the "how". This means the controller doesn't build queries, the repository does. You just ask it what you want and it magically delivers.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top