【问题标题】:MVC Update-database, Enable-Migrations problems after upgrading to EF6MVC 更新数据库,升级到 EF6 后的启用迁移问题
【发布时间】:2014-09-04 10:22:18
【问题描述】:

我已在我的 MVC 应用程序中升级到 EF6。

当我在 PM 控制台中尝试 Enable-Migrations 时。

在程序集“Cardsender02”中找不到上下文类型

我的解决方案中只有一个项目,而且在我看来,我确实有一个上下文。

namespace Cardsender02.Models
{
    public class CardContext : DbContext
    {
        public CardContext()
           : base("DefaultConnection")
        {}

那我试试

Enable-Migrations -ContextTypeName Cardsender02.Models.CardContext

但这给了我

“Cardsender02.Migrations.Configuration”类型不继承自 'System.Data.Entity.Migrations.DbMigrationsConfiguration'。迁移 配置类型必须从 'System.Data.Entity.Migrations.DbMigrationsConfiguration'。

现在该怎么办?

配置类:

namespace Cardsender02.Migrations
{
using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;

internal sealed class Configuration : DbMigrationsConfiguration<Cardsender02.Models.CardContext>
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = false;
    }

    protected override void Seed(Cardsender02.Models.CardContext context)
    {}
 }}

【问题讨论】:

  • 你需要一个继承自 DbMigrationsConfiguration 的类来配合你的上下文。
  • 我看不懂,请在添加代码时更新您的问题:)
  • @ThorOstergaard,click this linkCardContext 位于哪个项目中?
  • CardContext 位于解决方案中唯一的项目——CardSender02
  • 试试Enable-Migrations -verbose看看有没有有用的信息

标签: c# asp.net-mvc entity-framework code-first


【解决方案1】:

如果要升级到 EF6,请确保所有依赖项都已正确升级,包括程序集、配置和其他引用。

您可以使用此命令从包管理器控制台正确重新安装。

Update-Package –reinstall EntityFramework

【讨论】:

    猜你喜欢
    • 2016-04-09
    • 1970-01-01
    • 2014-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-09
    • 2016-09-07
    相关资源
    最近更新 更多