code first migration error in mvc

Posted by Klbaiju under ASP.NET MVC on 12/3/2019 | Points: 10 | Views : 1029 | Status : [Member] | Replies : 1
I want to use codefirst dataaccess in my MVC Application.

I have separated model classes and dbcontext in separate project in same application

My main application name is EFCodeFirstHarshaTest

model classes in Company1.DomainModels , which contains 3 classes

DbContext name is Company1.DomainModels following is the code for dbcontext

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
using Company1.DomainModels;

namespace Company1.DataLayer
public class Company1DbContext : DbContext

public Company1DbContext() : base("MyConnectionString")
// Database.SetInitializer(new MigrateDatabaseToLatestVersion<Company1DbContext, Configuration>());
public DbSet<Product> Products { get; set; }
public DbSet<Brand> Brands { get; set; }
public DbSet<Category> Categories { get; set; }

next I have selecte nuget packagemanager console

i have entered

PM> enable-migrations -ContextTypeName Company1.DataLayer.Company1DbContext

iam getting following result

The context type 'Company1.DataLayer.Company1DbContext' was not found in the assembly 'EFCodeFirstHarshaTest'

how to solve this




Posted by: Sheonarayan on: 12/3/2019 [Administrator] HonoraryPlatinum | Points: 25

It looks like namespace or assembly reference problem. See if Visual Studio is able to recognize your DbContext class. Add all the namespaces that is related with Identity (.NET MVC Project) and try to build the project first. If build is successful, it should work.

Sheo Narayan

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response