【问题标题】:Converting to Web Application Project: EntityFramework/DataAnnotations type exists error转换为 Web 应用程序项目:EntityFramework/DataAnnotations 类型存在错误
【发布时间】:2021-03-11 16:31:38
【问题描述】:

我正在努力将一个旧的网站项目转换为一个 Web 应用程序项目,我遇到了这个问题,编译器没有帮助我了解我需要查看或可能更改的内容。

这是错误的全文: “'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' 和 'System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 中都存在类型 'ColumnAttribute'”错误

这是cs文件中出现错误的行(在实体类中):

[Column(TypeName = "ntext")]
[Required]
public string r_roleDescription { get; set; }

带有“Column(TypeName...”的行以错误突出显示。

有什么想法吗?

【问题讨论】:

  • 这真的与从网站项目切换到 Web 应用程序项目无关。这只是两个不同程序集中的两个不同类使用相同名称的简单案例。解决方案是完全限定您的部分或全部类引用,或者在不需要时删除其中一个程序集,可能删除任何不必要的 using 语句等。您了解命名空间的工作原理吗?

标签: c# entity-framework data-annotations web-site-project web-application-project


【解决方案1】:

使用完整的命名空间路径来指定你真正想要使用的:

// If you want the DataAnnotation:
[System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "ntext")]
[Required]
public string r_roleDescription { get; set; }

编译器只需要你告诉它如何解决它,因为有两种可能性(实体和组件模型)。

【讨论】:

    【解决方案2】:

    感谢您的回复。事实证明,问题在于编译器由于错误太多而丢失。我将网站项目中的文件一次复制到 Web 应用程序项目中,修复出现的错误,然后这个错误就消失了。

    谢谢,

    【讨论】:

      猜你喜欢
      • 2011-05-28
      • 2010-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-12
      • 1970-01-01
      相关资源
      最近更新 更多