2011-02-16 56 views
0

這部分代碼工作正常ASP.NET MVC3 System.ComponentModel.DataAnnotations和協會

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

,但如果我在這個類

System.ComponentModel.DataAnnotations 

再加入,會找不到。

問題在哪裏?

回答

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

沒想到你可以做到這一點,謝謝@Domenic! – Austin 2011-03-15 18:42:27

1

看起來你有兩個衝突的命名空間。嘗試改變協會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; } 
}