我如何使用System.ComponentModel.DataAnnotations.AssociationAttribute [英] How do I use System.ComponentModel.DataAnnotations.AssociationAttribute

查看:154
本文介绍了我如何使用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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆