无法使用数据注释

时间:2015-05-27 03:55:28

标签: c# entity-framework-core

所以在这里我们试图在游戏开始之前处理EF7,我遇到了我只能称之为疯狂的事情。

在EF6中,我使用了相当多的注释,我试图将其转移到EF7中,根据UnicornStore项目,这是完全有效的,但是我遇到了一个问题,其中visual studio 2015抱怨我没有引用System.ComponentModel.DataAnnotations程序集。很公平,我添加了对程序集的引用,现在我从DNX Core 5.0获得以下内容:

Error   CS0234  The type or namespace name 'DataAnnotations' does not exist in the namespace 'System.ComponentModel' (are you missing an assembly reference?) Lib.DNX Core 5.0

对于我的生活,我无法弄清楚这里发生了什么,因为当我看到UnicornStore作为我的参考时,在project.json中没有对该程序集的引用,但是有一个引用project.lock.json,据我所知,你不应该编辑那个文件。

最重要的问题我做错了什么?为什么DNX 4.5.x不会抱怨引用而DNX Core 5.0呢?

3 个答案:

答案 0 :(得分:9)

我恰好在beta8中遇到了这个问题。我通过结合这里给出的其他答案和注释来解决它,以便为DNX 4.5.1和DNX Core 5.0提供交叉编译:

"frameworks": {
  "dnx451": {
    "frameworkAssemblies": {
      "System.ComponentModel.DataAnnotations": "4.0.0.0"
    },
    "dependencies": {
    }
  },
  "dnxcore50": {
    "dependencies": {
      "System.ComponentModel.Annotations": "4.0.11-beta-23409"
    }
  }
}

答案 1 :(得分:4)

.Net 4.6(也称为vNext)Web项目依赖于Microsoft.AspNet.Mvc。这会引入一个很大的依赖树,数据注释位于包Microsoft.DataAnnotations

在项目中使用数据注释使用Microsoft.DataAnnotations代替System.ComponantModel.DataAnnotations

答案 2 :(得分:1)

  "frameworks": {
    "dnx451": {
      "frameworkAssemblies": {
        "System.ComponentModel.DataAnnotations": "4.0.0.0"
      },
      "dependencies": {
      }
    }
  }