I am working with .net MVC. I have enabled migrations in my project which has successfully been done. But I'm getting an error in Migrations>Configrations.cs. The error is following.
CS0311: The type 'BabyStore.DAL.StoreContext' cannot be used as type parameter 'TContext' in the generic type or method 'DbMigrationsConfiguration'. There is no implicit reference conversion from 'BabyStore.DAL.StoreContext' to 'System.Data.Entity.DbContext'
I have enabled migration as following
PM>Enable-Migrations -ContextTypeName BabyStore.DAL.StoreContext
The code of BabyStore.DAL.ContextStore.cs is
namespace BabyStore.DAL
{
public class StoreContext
{
public DbSet<Product> Products { get; set; }
public DbSet<Category> Categories { get; set; }
}
}
And lastly The code where I'm getting error is following BabyStore.Migrations.Configurations.cs
namespace BabyStore.Migrations
{
using System.Data.Entity.Migrations;
internal sealed class Configuration : DbMigrationsConfiguration<BabyStore.DAL.StoreContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
}
protected override void Seed(BabyStore.DAL.StoreContext _context)
{
var categories = new List<Category>
{
new Category { Name = "Clothes"},
new Category { Name = "Play and Toy" }
};
categories.ForEach(c => _context.Categories.AddOrUpdate(p => p.Name, c));
_context.SaveChanges();
var products = new List<Product>
{
new Product {Name="Sleep Suit", Desccription="For Sleeping wear",Price=100,CategoryID=categories.Single(c=>c.Name=="Clouths").ID },
new Product {Name="Vest", Desccription="For Sleeping wear",Price=200,CategoryID=categories.Single(c=>c.Name=="Clouths").ID}
};
products.ForEach(c => _context.Products.AddOrUpdate(p => p.Name, c));
_context.SaveChange();
}
}
}
I'm getting error in internal sealed class Configuration : DbMigrationsConfiguration line