I've decided to use Entity Framework for O/R Mapping, and DataAnnotations for validation in my project, and I have now encountered an odd problem when trying to implement this.
This is what I've done:
I have the following entity type
Contact
*******
Int32 Id (not null, Entity Key)
Name Name (not null)
Address Address (not null)
String Phone
String Email
where Name and Address are complex types defined as follows:
Name Address
**** *******
String First (not null) String Street (not null)
String Last (not null) String ZipCode (not null)
String City (not null)
And the following classes reside in the same namespace as my entities:
public class ContactMetadata
{
[Required]
public Name Name { get; set; }
}
[MetadataType(typeof(ContactMetadata))]
partial class Contact { }
However, when I create a new Contact item, the Name and Address types are filled with instances of Name and Address where all values are null, instead of Name and Address having null values themselves. Thus, the Required attribute doesn't throw any errors, although all values are null. How do I work around this?