每个 System.ComponentModel.DataAnnotations 属性的用途是什么?
我正在使用带有 POCO 的实体框架 4 制作 MVC 3 应用程序。我想尽可能多地注释我的所有实体。然而,我遇到一个问题,我无法找到有关每个属性含义的良好文档。有些非常简单,例如 [Required]
或 [StringLength(...)]
。然而,对于像 [Association]
这样的属性,我并不是 100% 确定。我是否将其放在导航属性上?在外键属性上?仅在多对多关系上? thisKey
是该对象的主键还是该对象的外键?
我找不到任何好的资源来列出所有这些属性并提供很好的解释和示例。
对于关联,MSDN只是说:“指定一个实体成员代表一种数据关系,例如外键关系。”
“thisKey:关联的 thisKey 端的键值的属性名称的逗号分隔列表。”
我得到了有关其中一个属性的更具体问题的答案:
关联:如何使用 System.ComponentModel.DataAnnotations.AssociationAttribute
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AssociationAttribute 对于导航属性上的实体框架代码优先不执行任何操作。看起来似乎确实如此,但这实际上只是 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.