Page 1 of 1

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

Posted: Thu 25 Apr 2013 13:35
by EdB
Hi,

How do I validate dates in Ed via Data Annotations?

Also is it possible to extend the number of validators?

Thanks

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

Posted: Thu 25 Apr 2013 13:55
by EdB
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.

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

Posted: Thu 25 Apr 2013 13:57
by EdB
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;

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

Posted: Thu 25 Apr 2013 14:04
by EdB
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.

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

Posted: Mon 29 Apr 2013 16:23
by Shalex
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.