簡體   English   中英

ASP.NET MVC3 System.ComponentModel.DataAnnotations和Association

[英]ASP.NET MVC3 System.ComponentModel.DataAnnotations and Association

這部分代碼工作正常

[Association(Storage = "profile", ThisKey = "UserId", OtherKey = "UserId")]
public Profile User {
   get { return this.profile.Entity; }
   set { this.profile.Entity = value; }
}

但如果我加入這個課程

System.ComponentModel.DataAnnotations 

然后,無法找到協會。

問題出在哪兒 ?

看起來你有兩個沖突的命名空間。 嘗試將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; }
}

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM