Search code examples
entity-frameworkdata-annotationscode-firstfluent-interface

Entity Framework - Code First Fluent API: ErrorMessage?


I'd like to use localised validations with the Fluent API like this in Data Annotations:

[Required(ErrorMessageResourceName = "Domain_Address_AddressTypeRequired", ErrorMessageResourceType = typeof(Resources))]
public virtual  AddressType  AddressType  { get; set; }

Unfortunately the .IsRequied() has no overloaded version to give the error message like this:

.IsRequied("That was your last mistake! :D");

Is that possible? How?

Thank you

PumpeR1


Solution

  • No it is not possible.

    Close pairing with data annotations is one of the worst features in DbContext API. Mapping and validation should be two different independent functionalities. There was very good reason why Linq-to-SQL attribute mapping didn't use data annotations.