Required attribute not triggering an exception on SaveChanges()

This was a very interesting (and annoying at the same time). I was writing some integration tests and it turns out that the [Required] attribute doesn't trigger an exception on SaveChanges().

 

No exception raised. Instead, we can make the required property nullable.

This time we get: System.Data.Entity.Validation.DbEntityValidationException.

I did some digging and it turns out that the System.Data.Entity.Validation.DbEntityValidationException has been introuced in EF6.

Leave Comment

Your email address will not be published.

Please type the characters of this captcha image in the input box

Please type the characters of this captcha image in the input box