gpt4 book ai didi

asp.net-mvc-3 - 我如何使用System.ComponentModel.DataAnnotations.AssociationAttribute

转载 作者:行者123 更新时间:2023-12-04 03:46:13 25 4
gpt4 key购买 nike

前段时间我问了这个问题:What is the purpose of each of the System.ComponentModel.DataAnnotations attributes?

但是,我没有得到回复的运气。从要求提供有关每个数据注释属性的文档的意义上来说,这个问题有点宽泛。目前,我对Association属性最感兴趣。

我正在将ASP.NET MVC3与Entity Framework 4一起使用,并想对我的POCO进行注释。我在POCO中使用了外键(感觉有点不对劲,但似乎通常可以使用)。如何用Association属性注释POCO?我应该放在哪些属性上(Association属性和/或外键属性)?什么是thisKeyotherKey参数。 thisKey是此POCO key ,还是此POCO中的外键?

最后,什么将使用此属性? ASP.NET MVC中有东西吗?

提前致谢!

最佳答案

Silverlight中的WCF RIA服务使用AssociationAttribute(与ExternalReferenceAttribute结合使用)。使用此属性,客户端可以解析来自不同域的实体之间的关联。

我认为它特定于RIA服务。 Here演练了如何在WCF RIA服务中应用它。

一个简单的例子看起来像

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;}
}

关于asp.net-mvc-3 - 我如何使用System.ComponentModel.DataAnnotations.AssociationAttribute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5389603/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com