While running command enable-migrations in Package Manager Console, got this error:
No context type was found in the assembly 'Vidly'
I am using Visual Studio 2017. How to solve it?
In order to resolve the issue, please find below steps.
Add this namespace System.Data.Entity for DbContext reference
using System.Data.Entity;
namespace Vidly.Models
{
public class MyDBContext:DbContext
{
public MyDBContext()
{
}
public DbSet<Customer> Customers { get; set; } // My domain models
public DbSet<Movie> Movies { get; set; }// My domain models
}
}
Now open package manager console and type below command to enable migrations.
enable-migrations -contexttypename MyDBContext (MyDBContext is the name of the class we created in step1)
Hope this helps :)
Make sure you have set the Default Project, that is present at the top label with a dropdown in your Package Manager Console. And this project should contains your Entity Framework context.
You can check this post to find where Default Project drop down located.
So finaly your code should be like this,
Enable-Migrations -ProjectName MyContextProjectNameHere -StartUpProjectName MyStartUpProjectNameHere -Verbose
Hope it helps :)
I have encountered this problem a few times and in my case I
That fixed the problem for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With