我正在跟随一个制作dotnet 2 rest api的教程,并期望dotnet cli在dotnet ef update之后生成数据库。但是这并没有发生。
我有这个上下文类
public class DutchContext : DbContext
{
public DutchContext(DbContextOptions<DutchContext> options): base(options)
{
public DbSet<Product> Products { get; set; }
public DbSet<Order> Orders { get; set; }
}
}
这是我在 StartUp.cs 中调用 con 字符串的方式。
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<IMailService, NullMailService>();
// support for real mail service
services.AddMvc();
services.AddDbContext<DutchContext>(cfg =>
{
cfg.UseSqlServer(_config.GetConnectionString("ConnectionString"));
});
}
还有保存 con 字符串的 config.json 文件
{
"ConnectionStrings": {
"ConnectionString": "Server=(localdb)\\MSSQLLocalDB;Database=EstudoDotnetDB;Integrated Security=true;MultipleActiveResultSets=true"
}
}
这是我的本地数据库名称 > (localdb)\MSSQLLocalDB
终端输出如下
$ dotnet ef database update
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using 'C:\Users\dbeze\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 2.0.1-rtm-125 initialized 'DutchContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: None
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (10ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT OBJECT_ID(N'__EFMigrationsHistory');
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT OBJECT_ID(N'__EFMigrationsHistory');
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [MigrationId], [ProductVersion]
FROM [__EFMigrationsHistory]
ORDER BY [MigrationId];
info: Microsoft.EntityFrameworkCore.Migrations[20405]
No migrations were applied. The database is already up to date.
No migrations were applied. The database is already up to date.
Done.
有什么想法吗?
如果这是一个愚蠢的问题,很抱歉,我对dotnet 2还不熟悉。