【发布时间】:2016-04-06 00:32:52
【问题描述】:
我也有同样的问题。我在project.json 文件中添加了以下依赖项:
"dependencies": {
"EntityFramework": "7.0.0-beta4",
"EntityFramework.Core": "7.0.0-rc1-final",
"EntityFramework.SqlServer": "7.0.0-beta8",
"EntityFramework.Commands": "7.0.0-rc1-final"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel",
"ef": "EntityFramework.Commands"
},
...
我使用dnu install EntityFramework 和dnu install EntityFramework.SqlServer 来安装软件包。 "EntityFramework": "7.0.0-beta4", 由安装程序自己自动写入dependencies 节点下。
问题/问题 1:令我惊讶的是,当我为 EntityFramework 提取智能时,我展示的可用版本只有 6.1.3!
问题 2:当我使用 dnu build 编译我的应用程序时(我在 dependencies 节点下手动添加 EntityFramework 程序集(.Core 和 .Commands)后运行了 dnu restore 命令,我得到了一堆编译错误:
The type 'DbContextOptionsBuilder' is defined in an assembly that is not referenced. You must add a reference to assembly 'EntityFramework.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null'.
D:\Projects\aspnet\apiservice\Models\SampleData.cs(12,41): DNXCore,Version=v5.0 error CS0308: The non-generic method 'IServiceProvider.GetService(Type)' cannot be used with type arguments
D:\Projects\aspnet\apiservice\Models\SampleData.cs(13,32): DNXCore,Version=v5.0 error CS0308: The non-generic method 'IServiceProvider.GetService(Type)' cannot be used with type arguments
D:\Projects\aspnet\apiservice\Models\SampleData.cs(14,29): DNXCore,Version=v5.0 error CS1061: 'object' does not contain a definition for 'Books' and no extension method 'Books' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
D:\Projects\aspnet\apiservice\Models\SampleData.cs(15,42): DNXCore,Version=v5.0 error CS1061: 'object' does not contain a definition for 'Authors' and no extension method 'Authors' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
D:\Projects\aspnet\apiservice\Models\SampleData.cs(17,43): DNXCore,Version=v5.0 error CS1061: 'object' does not contain a definition for 'Authors' and no extension method 'Authors' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
D:\Projects\aspnet\apiservice\Models\SampleData.cs(19,45): DNXCore,Version=v5.0 error CS1061: 'object' does not contain a definition for 'Authors' and no extension method 'Authors' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
D:\Projects\aspnet\apiservice\Models\SampleData.cs(22,29): DNXCore,Version=v5.0 error CS1061: 'object' does not contain a definition for 'Books' and no extension method 'Books' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
D:\Projects\aspnet\apiservice\Models\SampleData.cs(61,29): DNXCore,Version=v5.0 error CS1061: 'object' does not contain a definition for 'SaveChanges' and no extension method 'SaveChanges' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
如果我删除 .Core 和 .Commands 程序集引用项目构建正常。
然后我将EntityFramework.Core 的版本更改为7.0.0.0,如错误中所述:
The type 'DbContextOptionsBuilder' is defined in an assembly that is not referenced. You must add a reference to assembly 'EntityFramework.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null'.
但是dnu restore 现在给了我以下信息:
Unable to locate Dependency EntityFramework.Core >= 7.0.0
Writing lock file D:\Projects\aspnet\apiservice\project.lock.json
Restore complete, 6675ms elapsed
Errors in D:\Projects\aspnet\apiservice\project.json
Unable to locate Dependency EntityFramework.Core >= 7.0.0
我是asp.net 5Visual Studio code平台的新手。而且我不能使用Visual Studio 2015,因为开发团队的其他成员正在使用 OSX。
这对我来说是一个学习项目。要求很简单。连接 SQL Server 数据库,使用 Entity Framework 拉取master-child 关系数据。
搞砸了!救命!!
提前致谢
更新
我可以看到
project.json中所有版本为7.0.0-rc1-final的软件包的主要变化。我使用 Yeoman 生成器工具创建项目,但看起来您通过Visual Studio更正了包。那么,我是否必须手动更新软件包版本并restore他们?Yeoman 创建/生成项目时,默认没有添加
global.json文件。我可以手动添加它并手动将代码放入其中吗?这行得通吗?我还可以看到在
project.json文件中添加了一些额外的包引用,这些引用是 Yeoman 生成器默认未添加的 - 例如Microsoft.AspNet.Tooling.Razor、Microsoft.Extensions.Logging.Console、Microsoft.Extensions.Logging.Debug、Microsoft.Extensions.Logging等。它们都在项目中得到有效使用吗?因为生成器没有自动添加它们,我可以手动添加它们并使用dnu restore恢复吗?如果我手动添加,这会对项目有什么影响吗?
【问题讨论】:
-
请不要在代码 sn-ps 不起作用时使用它们。
标签: c# asp.net asp.net-core entity-framework-core dnu