- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在学习一些关于如何使用 .netcore 设置我的第一个 web api 的教程。我在尝试运行我的第一次迁移时遇到问题:
PM> 添加迁移 InitialMigration
使用“1”个参数调用“.ctor”时出现异常:“参数‘frameworkName’不能为空字符串。
参数名称:frameworkName”
我的理解是说某处有一个构造函数,其中一个参数为空;但是,我不知道这个“frameworkName”参数在哪里。我假设这是某种内部 EF 机制。
此错误消息引用的是什么类?
这是我的简单实体设置
public class ShackupContext : DbContext
{
public DbSet<Post> Posts { get; set; }
public ShackupContext(DbContextOptions<ShackupContext> options):base(options)
{
}
}
public class Post
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Required]
[MaxLength(200)]
public string Name { get; set; }
}
更新 1我已经更新了我的 dbcontext 以按照@ViktorsTelle 的建议调用基类构造函数。
我的项目设置与我遵循的任何教程都不同。主要区别是我的实体包含在它们自己的项目中,而不是在 api 项目本身中。
这让我相信在 Shackup.Data 项目上运行 Add-Migration 本身不需要我在我的 api 项目中注册我的 dbcontext。无论如何,我还是这样做了,看看会发生什么:
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
services.AddDbContext<ShackupContext>(o =>
o.UseNpgsql(Configuration["connectionStrings:postgres"],
a => a.MigrationsAssembly("Shackup.Data")));
}
一旦我这样做了,我就设法在迁移过程中取得了一些进展。我现在得到PM> 添加迁移 InitialMigration
指定的 deps.json [C:\Users\campo\Documents\Visual Studio 2015\Projects\Shackup\src\Shackup.Api\bin\Debug\netcoreapp1.1\Shackup.Api.deps.json] 不存在
进程以非零退出代码结束
所以我查看了那个目录,确实它缺少文件;但是,该文件正在输出到该目录的子文件夹中。
deps.json 文件位于 win10-x64 文件夹内。我可以简单地复制并粘贴到所需的文件夹,但现在我面临一个新问题:
为什么 Nuget 包管理器控制台在错误的目录中查找?
或者可能:我如何更改它以在正确的位置显示?
更新 2
我已经更新了两个项目中的所有项目依赖项。下面是数据和api项目的两个文件
API
{
"dependencies": {
"Microsoft.AspNetCore.Mvc": "1.1.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
"Microsoft.EntityFrameworkCore": "1.1.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
"Microsoft.Extensions.Configuration.Json": "1.1.0",
"Microsoft.Extensions.Logging": "1.1.0",
"Microsoft.Extensions.Logging.Console": "1.1.0",
"Microsoft.Extensions.Logging.Debug": "1.1.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
"Microsoft.NETCore.App": "1.1.0",
"Shackup.Data": "1.0.0-*",
"Npgsql.EntityFrameworkCore.PostgreSQL": "1.1.0",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final"
},
"frameworks": {
"netcoreapp1.1": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"runtimes": {
"win10-x64": {},
"win81-x64": {}
},
"publishOptions": {
"include": [
"wwwroot",
"**/*.cshtml",
"appsettings.json",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
数据
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.EntityFrameworkCore": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"NETStandard.Library": "1.6.1"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final"
}
}
最佳答案
在您的解决方案中选择合适的启动项目:在解决方案资源管理器中右键单击您的项目,选择“设置为启动项目”
关于c# - EF 迁移 : The parameter 'frameworkName' cannot be an empty string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41269395/
最近无缘无故,我的 VS2012 设计器无法打开项目中的 xaml 文件。他们之前都工作正常。我没有更改项目设置或安装 vs 更新(使用更新 4)。 我得到的错误是:系统参数异常:参数“framewo
我正在学习一些关于如何使用 .netcore 设置我的第一个 web api 的教程。我在尝试运行我的第一次迁移时遇到问题: PM> 添加迁移 InitialMigration 使用“1”个参数调用“
我正在使用: Visual Studio 2017 v15.5.4 NUnit 3.9.0 NUnit 测试适配器 3.9.0 Resharper 2017.3 .Net 4.7项目 尝试调试 NUn
使用预发布的 EF Core (3.0.0-preview6.19304.10)。当我调用 DbContext.SaveChanges() 时,它会导致错误 Value cannot be null.
使用预发布的 EF Core (3.0.0-preview6.19304.10)。当我调用 DbContext.SaveChanges() 时,它会导致错误 Value cannot be null.
更新到 Xcode 12 后,项目在模拟器上构建时给了我这个错误: Could not find module 'FrameworkName' for target 'arm64-apple-ios-
我更新到 Xcode 6.3,我的工作区中有两个独立的项目(一个是框架)。现在,Xcode 自动生成了这个“frameworkname”-Swift.h 头文件,但是当我有一个通用类作为属性时,它会生
我是一名优秀的程序员,十分优秀!