Matthijs Wessels
Matthijs Wessels

Reputation: 6729

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.AssociationAttribute

Upvotes: 3

Views: 842

Answers (1)

diegohb
diegohb

Reputation: 1887

The 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.

Upvotes: 1

Related Questions