Custom validation unique property - generic classes

后端 未结 3 1328
感动是毒
感动是毒 2021-02-15 05:42

I\'m trying to make a custom validation [IsUnique]. That check if is property value is unique and return a proper message.

This is my code, but this only work for a spec

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-15 06:47

    I think the best way is to let the database do its works.

    Create a constraint in the database to prevent two articles have the same name (or whatever uniqueness you need). Then, when the user create a new article or update an existing one with an existing article name, the database will throw an exception. Catch that exception and let the user knows about the issue.

提交回复
热议问题