这部分代码工作正常
[Association(Storage = "profile", ThisKey = "UserId", OtherKey = "UserId")]
public Profile User {
get { return this.profile.Entity; }
set { this.profile.Entity = value; }
}
但如果我在这个课程中添加
System.ComponentModel.DataAnnotations
然后,找不到协会。
问题出在哪里?
答案 0 :(得分:1)
看起来你有两个冲突的命名空间。尝试将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; }
}
答案 1 :(得分:1)
对奥斯汀答案的改进是使用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; }
}