c# - Error message for Index data annotation in EF -
Hello I am using the unit framework 6.1.1 which supports the index data annotation feature in it. I have a field defined in my unit class:
[index ("score index", isunik = true)] public at score {get; Set; } This is working fine, however, when the score is not unique then I am trying to find out how to display a message. Right now it just throws an exception.
but it is not
[index ("scoreIndex", isUnique = true, ErrorMessage = "score should be unique"]] The error message for this index annotation class is defined. Can you please tell me how to handle the exception message so that it can handle it satisfactorily?
index entry is not a validation feature, and this is the reason for the error message And does not have an IsValid () method that is valid against a range of valid values. This means that it did not valid like the specific validation attributes (required, maxlength etc.) The IsUnique attribute is used only during a table creation to create a unique index.
If you want to use the attributes, Specificity check To create a custom attribute, this index will definitely be the successor to the validation property class, and in order to check the specificity in the attribute verification code, EF DBCTNtex will be accessed internally. If you do not like it, the data-annotation approach, and it is very complicated, then you trycanges () method by decoding a try-catch block, error message and friendly return to your visual-model You can handle DbUpdateException . try {use (var ac = new ApplicationDbContext ()) // // non-unique data AC. Add Save Chain (); }} Hold (DbUpdateException ex) {// handle index error}
Comments
Post a Comment