tags:

views:

34

answers:

2

I have a project in Asp net mvc. An entity called product can not have similar titles. As I am following repository pattern where is the best place to check the duplication?

I can do it in controller but it will lead to a fat controller.

+1  A: 

I presume you're using a DB server? Put a unique constraint on the DB column. Doing this in the repository or controller introduces concurrency issues (another transaction, which you can't see since it's not committed yet, could have already inserted a duplicate value). Constraints can see through this.

Craig Stuntz
Actually I am using DDD and LinQ. we are using createDatabase method and I am not able to enforce unique constraint from dbml
Tinku
The DB server will enforce the constraint. You don't need to reimplement DB server functionality.
Craig Stuntz
+1  A: 

If it is a very hard and fast rule, backing it with a database constraint is highly advisable--that will back-stop your code and make sure no slip-ups get through.

Insofar as enforcing the rule in code, how are you currently handling validation? This definitely falls into that category.

Wyatt Barnett