【发布时间】:2017-05-25 14:35:07
【问题描述】:
我是第一次尝试 EF Core,并且编写了一个非常简单的 MVC 应用程序来让我的脚湿透。我正在使用一种方法为UnicornStore project 中的数据库播种,他们在Startup.cs 中编写了一些代码来迁移数据库,然后运行种子方法。
在他们调用种子方法之前,他们运行这个DbContext扩展方法来检查是否所有的迁移都被应用了:
using System;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
namespace UnicornStore.Models
{
public static class DbContextExtensions
{
public static bool AllMigrationsApplied(this DbContext context)
{
var applied = context.GetService<IHistoryRepository>()
.GetAppliedMigrations()
.Select(m => m.MigrationId);
var total = context.GetService<IMigrationsAssembly>()
.Migrations
.Select(m => m.Key);
return !total.Except(applied).Any();
}
}
}
我已经在我的应用程序中使用了同样的方法并且一切正常——代码编译并且数据库被迁移和播种。但是,Visual Studio (2017 Enterprise) 是红色下划线的:
context.GetService<IMigrationsAssembly>()
.Migrations
.Select(m => m.Key);
如果我将鼠标悬停在红线上,它会告诉我:
模块'System.Private.CoreLib,版本=4.0.0.0,文化=中性, PublicKeyToken=foo' 应该被引用
谁能告诉我为什么我会收到这条消息?我实际上尝试添加对System.Private.CoreLib 的引用以查看会发生什么,这导致了大量错误(未定义的System.Object 等)。如果他们以后再来咬我,我总是不愿意让这样的事情悬而未决,所以任何解决方案(或确认我可以留下这个并忽略该消息)将不胜感激!
【问题讨论】:
标签: visual-studio asp.net-core asp.net-core-mvc entity-framework-core