How do I add a Validation for Date to my Property?

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
EdB
Posts: 91
Joined: Mon 15 Oct 2012 09:24

How do I add a Validation for Date to my Property?

Post by EdB » Thu 25 Apr 2013 13:35

Hi,

How do I validate dates in Ed via Data Annotations?

Also is it possible to extend the number of validators? I see a useful list at http://dataannotationsextensions.org.

Thanks

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

Re: How do I add a Validation for Date to my Property?

Post by EdB » Thu 25 Apr 2013 13:55

Hi,

I have just revisited one of my old posts to do with the use of "Attributes" which looks great apart from the fact I cannot get it to work in the MVC3 application. Also should these validations trigger in the "Retrieve Data" Grid in ED, as they do not seem to be doing so. Again it would be neat if this were possible since one could test the complete functionality of the Entity before it gets code generated to a POCO.

Many thanks.

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

Re: How do I add a Validation for Date to my Property?

Post by EdB » Thu 25 Apr 2013 13:57

My generated code for the date validation. Should this work?

[System.ComponentModel.DataAnnotations.DataType(System.ComponentModel.DataAnnotations.DataType.Date, ErrorMessage = @"Not a valid date")]
public virtual string DateOfBirth
{
get
{
return _DateOfBirth;
}
set
{
_DateOfBirth = value;
}
}
private string _DateOfBirth;

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

Re: How do I add a Validation for Date to my Property?

Post by EdB » Thu 25 Apr 2013 14:04

The Required Validators are working, but this date does not. Is it to do with the fact that the property is a string?

Ideally I want to validate for a correct date and then store as a string.

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

Re: How do I add a Validation for Date to my Property?

Post by Shalex » Mon 29 Apr 2013 16:23

Please specify the problem with code generation made by Entity Developer you have encountered (how it actually generates the attribute and how it should). If possible, send us a small test model to reproduce the issue in our environment.

Be aware that a new Data Annotation Metadata template, generating Data Annotation metadata classes and decorating classes and properties with data annotation attributes for validation, presentation and defining metadata, is added to the set of standard templates of Entity Developer starting from the 5.5 version.

Post Reply