Validation Error Messages for Internationalization

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
Pierre
Posts: 4
Joined: Fri 01 Jul 2016 07:41

Validation Error Messages for Internationalization

Post by Pierre » Tue 28 Feb 2017 16:12

Hi

I'm using Database First to create my model with the template 'DbContext'. I want to translate the Error Message provides by the context when i'm calling the 'GetValidationErrors()' (in EF6)

After research, I have seen that i could change messages return by this method in the template by changing the 'Validation Error Messages'. Unfortunately, I don't understand how it works. If i'm writing what I want in the field (for example : Required Message = 'hello') the hello error message is not returned by the method and it's always the 'hard coded error message'.

So can you show me an example on how to change this validation error message for another language ? I will make my program in Multi Language so could you please (if it's not too much) explain me an example for multi language.

Thanks for your helps,

Regards,

Pierre.

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Re: Validation Error Messages for Internationalization

Post by Shalex » Thu 02 Mar 2017 09:47

Please refer to viewtopic.php?f=30&t=28617. Does this help?

Pierre
Posts: 4
Joined: Fri 01 Jul 2016 07:41

Re: Validation Error Messages for Internationalization

Post by Pierre » Tue 07 Mar 2017 10:40

Hi,

Thanks for the answer.

Unfortunately, I'v seen this topic before and it didn't work in my case.

In my template (DbContext), I have choosen the 'Data Annotation' for the validation framework property and I have writen my personnal error message in each Error Message , but no one appears when the error is detected. That's why I'm a little disappointed.

I have another problem with the validate rules on property. When I have a validate property which is not in the property (For example MaxLength is in the property and there is a validate rule for MaxLength, but for MinLength, there is just a validate rule), the validation isn't working. (For example, I have writen '2' for the MinLength, but a length of 1 is accepted).

Maybe I'm not using the validate rule on a property in my model in the right way. It's like my context doesn't care about the devart model.

I also want to know if there is the possibility to access to this metadata by code. I can find the facets of my entity (Nullable, MaxLength, FixedLength,...) but not to the validate rules ?

Code: Select all

 
var oc = ((IObjectContextAdapter)context).ObjectContext;           
MetadataWorkspace workspace = oc.MetadataWorkspace;
IEnumerable<EntityType> tables = workspace.GetItems<EntityType>(DataSpace.SSpace);
 var facets= tables.First().Properties[0].TypeUsage.Facets;


What can I do to access to the validate rules in my model ?

Best regards,

Pierre

PS : Sorry for my english, I hope I'm enough clearly :oops: .

Pierre
Posts: 4
Joined: Fri 01 Jul 2016 07:41

Re: Validation Error Messages for Internationalization

Post by Pierre » Wed 08 Mar 2017 08:15

Hi,

I have solved my problem and everything works now :).

Thanks for the answer,

Pierre.

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Re: Validation Error Messages for Internationalization

Post by Shalex » Fri 10 Mar 2017 11:23

Thank you for letting us know.

Post Reply