开发者

checking duplication of the title of an entity

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 duplica开发者_开发百科tion?

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜