C# – No context type found in the assembly. ASP.NET MVC4


Was following this tutorial here (wanted a database of customers instead of movies as per tutorial):

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'."

This is my customer model:

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"

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 🙂

Best Solution

You don't have MvcCustomer namespace. From your code it is clear that you are using MvcVault namespace. Change this:

Enable-Migrations -ContextTypeName MvcCustomer.Models.CustomerDbContext

To this:

Enable-Migrations -ContextTypeName MvcVault.Models.CustomerDbContext

And it should work.

Alternatively, you can change MvcVault to MvcCustomer.