在程序集中找不到上下文类型.ASP.NET MVC4 [英] No context type found in the assembly. ASP.NET MVC4

查看:21
本文介绍了在程序集中找不到上下文类型.ASP.NET MVC4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此处遵循本教程(根据教程需要客户数据库而不是电影):http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a-new-field-to-the-movie-模型和表格

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

但是,当我尝试运行迁移命令时遇到以下错误:在程序集MvcVault"中找不到上下文类型MvcCustomer.Models.CustomerDbContext"."

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:

"Enable-Migrations -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...

任何帮助都会受到赞赏!谢谢你:)

Any help would be appreaciated! Thank you kindly :)

推荐答案

在我的项目中,我拼错了项目名称,所以根据培训文档,它找不到类,尝试使用

In my project, I spell wrong project name, so according the training document, it can't find the class, try just use

Enable-Migrations -ContextTypeName CustomerDBContext

有时 VS 可以搜索它,如果这有效,您的命名空间可能没有遵循本书

sometimes VS can search it, if this works, you namespace maybe not following the book

这篇关于在程序集中找不到上下文类型.ASP.NET MVC4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆