I have EF poco classproperty which has the DataAnnotatins. They include the FK, mandatory, maxlength conditions.
[Required(ErrorMessage = "Company name cannot be empty")] [StringLength(128, ErrorMessage = "The CompanyName should be less than 128 characters or less.")] [Index(IsUnique = true)] public string CompanyName { get; set; }
I am trying to move all these into EntityTypeConfigurations and am struggling to move the ErrorMessages.
Can any one give me a pointer on how to get this done>
答案 0 :(得分:1)
As you can read here, constraints configured by fluent mappings will by evaluated only in the context. They don't trickle through to the UI, as data annotations do (when used with the correct framework). So the EF team figured it wouldn't make sense to craft a user-friendly error message here. The validation will just throw a standard DbValidationError
saying something like
The field Name must be a string or array type with a maximum length of '128'
So you need the annotations if you want your own custom messages.