没有在装配中的上下文类型。 ASP.NET MVC4 [英] No context type found in the assembly. ASP.NET MVC4
问题描述
在这里按照本教程(想顾客,而不是电影,每教程的数据库):
<一href=\"http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a-new-field-to-the-movie-model-and-table\" rel=\"nofollow\">http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a-new-field-to-the-movie-model-and-table
Was following this tutorial here (wanted a database of customers instead of movies as per tutorial): http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a-new-field-to-the-movie-model-and-table
然而,当我尝试运行迁移命令时遇到以下错误:
上下文类型MvcCustomer.Models.CustomerDbContext'未在程序集MvcVault'发现。
However when I attempt to run migrations commands the following error is encountered: "The context type 'MvcCustomer.Models.CustomerDbContext' was not found in the assembly 'MvcVault'."
这是我的客户模型:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace MvcVault.Models
{
public class Customer
{
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime Born { get; set; }
public int Telephone { get; set; }
public string Email { get; set; }
}
public class CustomerDBContext : DbContext
{
public DbSet<Customer> Customers { get; set; }
}
}
我已经试过了第一迁移命令的各种组合,其中包括:
I've tried various combinations of that first migrations command, including:
启用的迁移-ContextTypeName MvcCustomer.Models.CustomerDbContext
"Enable-Migrations -ContextTypeName MvcCustomer.Models.CustomerDbContext"
启用的迁移-ContextTypeName MVCCustomer.Models.CustomerDbContext
"Enable-Migrations -ContextTypeName MVCCustomer.Models.CustomerDbContext"
不管怎样,我完全新的这一切,并很茫然。当编码了电影模式下的tutes,而且不知道为什么它不工作,如果我改名字,我是能够成功地完成这些教程等等...
Anyway, I'm completely new to all of this and am at a loss. I was able to successfully complete these tutorials when coding up the Movies model following the tutes, and have no idea why its not working if I change the name, etc...
任何帮助将是AP preaciated!衷心感谢你:)
Any help would be appreaciated! Thank you kindly :)
推荐答案
这是迟到的答复,但也许这将帮助别人的未来。
it is late reply but probably it will help someone in future.
从Web.config文件删除连接字符串,如果他们有一个以上的和没有必要的。只保留一个。
尝试在包管理器控制台运行的默认命令。
像启用的迁移
或
使用自动迁移使用此命令启用的迁移-EnableAutomaticMigrations
。
Remove connection strings from Web.config IF they are more than one and not needed. Keep only one.
Try running default command in Package Manager Console.
like Enable-Migrations
OR
To use auto migrations use this command Enable-Migrations -EnableAutomaticMigrations
.
这篇关于没有在装配中的上下文类型。 ASP.NET MVC4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!