【问题标题】:ASP.NET MVC3 System.ComponentModel.DataAnnotations and AssociationASP.NET MVC3 System.ComponentModel.DataAnnotations 和关联
【发布时间】:2011-02-16 10:28:42
【问题描述】:
这部分代码运行良好
[Association(Storage = "profile", ThisKey = "UserId", OtherKey = "UserId")]
public Profile User {
get { return this.profile.Entity; }
set { this.profile.Entity = value; }
}
但是如果我在这个类中添加
System.ComponentModel.DataAnnotations
那么,无法找到关联。
问题出在哪里?
【问题讨论】:
标签:
c#
asp.net
asp.net-mvc-3
data-annotations
【解决方案1】:
对 Austin 的回答的一个改进是使用 using 语句:
using L2SAssociation = System.Data.Linq.Mapping.Association;
[L2SAssociation(Storage = "profile", ThisKey = "UserId", OtherKey = "UserId")]
public Profile User
{
get { return this.profile.Entity; }
set { this.profile.Entity = value; }
}
【解决方案2】:
看起来您有两个冲突的命名空间。尝试将 Association 更改为 System.Data.Linq.Mapping.Association,如下所示:
[System.Data.Linq.Mapping.Association(Storage = "profile", ThisKey = "UserId", OtherKey = "UserId")]
public Profile User {
get { return this.profile.Entity; }
set { this.profile.Entity = value; }
}