简体   繁体   中英

ASP.NET MVC3 System.ComponentModel.DataAnnotations and Association

This part of code works fine

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

but if i add in this class

System.ComponentModel.DataAnnotations 

then, Association could not be found.

Where is the problem ?

It looks like you've got two namespaces that are conflicting. Try changing Association to System.Data.Linq.Mapping.Association, so it would look like:

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

An enhancement to Austin's answer is to employ the using statement:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM