【发布时间】: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 link。
CardContext位于哪个项目中? -
CardContext 位于解决方案中唯一的项目——CardSender02
-
试试
Enable-Migrations -verbose看看有没有有用的信息
标签: c# asp.net-mvc entity-framework code-first