Checking for Uniqueness of a entity property RRS feed

  • Question

  • In entity framework code migrations i realize that unique indexes can be added to columns.But when an attempt is made to insert a duplicate value you get back error message from the data based  in an SQL Exception wrapped in  UpdateException.
    This is not very user friendly to display to a user.

    Is it best to query the database for the existence of the value  and display a user friend error message?

    If not, Is there a more intuitive way of  doing uniqueness checks and displaying a user friendly error message ?

    Monday, January 21, 2013 6:24 PM


  • You may check for the existence and display an error message, but you should not expect this to work always. The duplicate may be inserted between the check and the insert/update.

    You'll have to catch the exception and turn it into a nicer error message.

    A Perl developer in the world of C#

    • Marked as answer by Alexander Sun Wednesday, January 30, 2013 8:39 AM
    Tuesday, January 22, 2013 9:55 AM