How to add a custom "Required" message? Is there an issue here?

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
EdB
Posts: 92
Joined: Mon 15 Oct 2012 09:24

How to add a custom "Required" message? Is there an issue here?

Post by EdB » Mon 30 Dec 2013 17:23

I am using v5.5.185 of ED.

I want to customise the "Required" validation message. The property is marked up as "Required". I went into "Attributes" for Diagram, Class and Property level and selected the "Required" data annotation, specified the "Error Text". Diagram and Class values caused a compile error in VS2012. Only specifying the error message at property level work.

However I also noted that this causes a "Duplicate" "required" annotation error in VS, until I specified that this property was not required by unchecking the required checkbox in the ED property editor. This worked, but it now looks as if this property is not required, unless one looks deeply into attributes for the custom "Required" attribute error message. Is this an issue with ED, or its design?

So what is the best method to implement custom "required" messages. It seems that you can only define the property has "Required" validation, but not what the message is.

Thanks,

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

Re: How to add a custom "Required" message? Is there an issue here?

Post by Shalex » Tue 31 Dec 2013 11:09

There are two ways to add attributes via interface of Entity Developer:

1. Validation Framework
a) open Tools > Entity Developer > Model Explorer > the Templates node, select your template, navigate to its properties:
-> set the Validation Framework property (e.g., to Data Annotations)
-> open Validation Error Messages and specify the text for Required Message
b) set Validate Required=True for a particular class property

2. Custom Attributes
a) navigate to Model > Settings > Attributes > select the assembly with the needed attributes and make sure that the needed attributes are checked in the window below, press OK
b) select the needed attribute in the Attributes collection of a particular class property

The [1] approach is easier to use. If [1] doesn't cover your needs, you can add attributes in the way which is described in [2].
EdB wrote:However I also noted that this causes a "Duplicate" "required" annotation error in VS
Seems like you employed the Required attribute using [1] and [2] approaches simultaneously.

EdB
Posts: 92
Joined: Mon 15 Oct 2012 09:24

Re: How to add a custom "Required" message? Is there an issue here?

Post by EdB » Wed 08 Jan 2014 14:48

Ok, Thanks for this. Will try out.

Post Reply