Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 788
Oszkar Avatar asked Dec 18 '11 16:12

Oszkar


1 Answers

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.

like image 101
Ladislav Mrnka Avatar answered Nov 15 '22 08:11

Ladislav Mrnka