cachet.net
cachet.net

Reputation: 320

MVC Repository pattern and UOW

I am working on project with MVC Repository Pattern. I have created a generic repository for CRUD operation. My questions are:-

  1. Do I need to create a separate UOW class for each entity or Should I create generic repository object in controller. (Both are working)

  2. In case if I have an entity/table that are fetching and updating based on foreign key instead of Primary key what should I do in that case. (I think in that need to create normal repository class)

Thanks

Upvotes: 0

Views: 169

Answers (1)

Kirill Bestemyanov
Kirill Bestemyanov

Reputation: 11964

Short answer on first question: it depends.

  • If your UoW just wrap repository object and do nothing else, you should not add this (UoW) abstraction to your code.

  • Else, if you have some special code that should be executed before saving and is not database code (something like domain validation or other), you should add UoW and put this code in it.

Second question seems that you set wrong column as Primary Key. May be your Foreign Key column should be also PrimaryKey?

Upvotes: 2

Related Questions