What is the purpose of each of the System.ComponentModel.DataAnnotations attributes?
I am making an MVC 3 application using entity framework 4 with POCOs. I want to annotate all my entitys as much as possible. I am having a problem however that I cannot find good documentation on the meaning of every attribute. Some are pretty straight forward, like [Required]
or [StringLength(...)]
. With attributes like [Association]
however, I am not 100% sure. Do I put it on a navigation property? On a foreign key property? Only on many to many relations? Is thisKey
the primary key of this object or the foreign key in this object?
I cannot find any good resource which lists all these properties with a good explanation and examples.
For association, MSDN just says:"Specifies that an entity member represents a data relationship, such as a foreign key relationship."
and "thisKey: A comma-separated list of开发者_如何转开发 the property names of the key values on the thisKey side of the association."I got an answer to a more specific question about one of the attributes:
Association: How do I use System.ComponentModel.DataAnnotations.AssociationAttributeThe AssociationAttribute does nothing for entity framework code-first on a navigation property. It may seem like it does, but it's really just EF's convention-based logic for creating the db.
精彩评论