【问题标题】:Duplicate Attribute in Entity Framework and Data Annotation error实体框架中的重复属性和数据注释错误
【发布时间】:2018-11-06 18:11:40
【问题描述】:

我有一个 MVC5 应用程序在 VS2017 的 .NET 框架 4.7.1 上运行。

当我构建我的应用程序时,我遇到了以下错误。有关如何解决此问题的任何建议?

“EntityFramework”中都存在“TableAttribute”类型, 版本=6.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089' 和 'System.ComponentModel.DataAnnotations,版本=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

Attribute error

project references

project references

project references

【问题讨论】:

  • 您应该通过以下方式明确表达您正在使用哪些 TableAttributes:[System.ComponentModel.DataAnnotations.Table] 或正确定义 using 子句。
  • @RistoM 这是我添加的使用类。使用系统;使用 System.Collections.Generic;使用 System.ComponentModel.DataAnnotations;使用 System.ComponentModel.DataAnnotations.Schema;
  • 也许可以按照@RistoM 的建议尝试 - [System.ComponentModel.DataAnnotations.Table] :)
  • @DavidHruška,试过....不工作
  • 你能把这个错误发生的代码行截图吗?正如其他人所说 - 错误是 [Table] 属性在代码中使用的多个命名空间中定义。因此它会导致一些错误。

标签: c# asp.net-mvc-5 compiler-errors .net-framework-version


【解决方案1】:

从参考列表中删除“System.ComponentModel.DataAnnotations” 删除数据注释使用的所有属性,例如 [Key],[StringLength].. 也运行

PM> update-package -reinstall

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-10
    相关资源
    最近更新 更多