我如何使用System.ComponentModel.DataAnnotations.AssociationAttribute [英] How do I use System.ComponentModel.DataAnnotations.AssociationAttribute
问题描述
前段时间我问这个问题:<一href=\"http://stackoverflow.com/questions/5076027/what-is-the-purpose-of-each-of-the-system-componentmodel-dataannotations-attribut\">What是每个System.ComponentModel.DataAnnotations的目的属性?
不过,我不得不与得到的答复没有运气。这个问题是在这个意义上有点笼统,要求大约每dataannotation属性文件。在这一刻,我在协会
属性最感兴趣。
我使用ASP.NET MVC3与实体框架4,想我的注释波苏斯。我使用外键在我的波苏斯(莫名其妙的感觉错了,但它似乎被普遍accepeted)。我该如何标注我的POCO与协会
属性?在哪些属性我把它(协会
财产和/或外键属性)?什么是 thisKey
和 otherKey
参数。为 thisKey
这波苏斯键,或在这种POCO外键?
那么最后,你会使用这个属性?有东西在ASP.NET MVC?
在此先感谢!
解决方案
该AssociationAttribute(中一起选择与ExternalReferenceAttribute)是在Silverlight使用WCF RIA服务
我觉得是具体到RIA服务。 这'sa演练如何获得在WCF RIA服务应用。
一个简单的例子看起来像
公共类客户{
公众诠释标识{获取;设置;}
}公共类订单{ 公众诠释标识{获取;设置;} 公众诠释客户编号{获取;集;} //客户的ForeignKey的 [ExternalReference]
[公会(客户,客户ID,ID)]
公众客户{获取;设置;}
}
Some time ago I asked this question: What is the purpose of each of the System.ComponentModel.DataAnnotations attributes?
However, I had no luck with getting replies. This question was a bit broad in the sense that it asked for documentation about every dataannotation attribute. At this moment, I am mostly interested in the Association
attribute.
I am using ASP.NET MVC3 with Entity Framework 4 and would like to annotate my POCOs. I am using foreign keys in my POCOs (somehow feels wrong, but it seems to be generally accepeted). How do I annotate my POCO with the Association
attribute? On which properties do I put it (Association
property and/or foreign key property)? What are the thisKey
and otherKey
parameters. Is thisKey
this POCOs key, or the foreign key in this POCO?
Then lastly, what will use this attribute? Is there something in ASP.NET MVC?
Thanks in advance!
The AssociationAttribute (in conjuction with the ExternalReferenceAttribute) is used by WCF RIA Services in Silverlight. With this attribute the client can resolve associations between entities from diffrent Domains.
I think it is specific to RIA Services. Here´s a walkthrough how it gets applied in WCF RIA Services.
A simple Example looks like
public class Customer{
public int Id {get;set;}
}
public class Order{
public int Id {get;set;}
public int CustomerId {get;set;} //ForeignKey of the Customer
[ExternalReference]
[Association("Customer", "CustomerId", "Id")]
public Customer {get;set;}
}
这篇关于我如何使用System.ComponentModel.DataAnnotations.AssociationAttribute的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!