每个System.ComponentModel.DataAnnotations属性的目的是什么? [英] What is the purpose of each of the System.ComponentModel.DataAnnotations attributes?
问题描述
我想提出一个MVC 3应用程序使用实体框架4波苏斯。我想诠释我所有的实体的尽可能多的。我有一个问题,但是我无法找到每个属性的含义好的文档。有些是pretty的直线前进,如 [必需]
或 [StringLength(...)]
。有了这样属性[公会]
不过,我不是100%肯定。难道我把它放在一个导航属性?在一个外键的财产?只有在多对多的关系?为 thisKey
此对象或主键此对象中的外键?
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.
有关协会,MSDN只是说:指定的实体成员重新presents数据关系,比如一个外键关系
和thisKey:对协会的thisKey侧键值的属性名称的逗号分隔的列表。
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."
我得到一个答案,关于属性的一个更具体的问题:
协会:<一href="http://stackoverflow.com/questions/5389603/how-do-i-use-system-componentmodel-dataannotations-associationattribute">How我用System.ComponentModel.DataAnnotations.AssociationAttribute
I got an answer to a more specific question about one of the attributes:
Association: How do I use System.ComponentModel.DataAnnotations.AssociationAttribute
推荐答案
在AssociationAttribute做一个导航属性没有为实体框架code-第一。它可能看起来像它,但它确实创造了分贝只是EF的惯例为基础的逻辑。
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.
这篇关于每个System.ComponentModel.DataAnnotations属性的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!