ASP.NET MVC3 System.ComponentModel.DataAnnotations 和关联

发布于 2024-10-17 09:40:54 字数 340 浏览 3 评论 0原文

这部分代码工作正常,

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

但如果我添加到此类中

System.ComponentModel.DataAnnotations 

,则无法找到关联。

问题出在哪里?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一曲爱恨情仇 2024-10-24 09:40:54

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

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; }
}
会傲 2024-10-24 09:40:54

看起来您有两个冲突的名称空间。尝试将 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; }
}

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; }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文