I can’t do migrations in EF Core.
I try
enable-migrations -contexttypename Bulky.DataAccess.ApplicationDBContext
and I get:
The type ‘ApplicationDBContext’ does not inherit from DbContext. The DbMigrationsConfiguration.ContextType property must be set to a type that inherits from DbContext
Here is the DbContext
file:
using Bulky.Models;
using Microsoft.EntityFrameworkCore;
namespace Bulky.DataAccess
{
public class ApplicationDBContext: DbContext
{
public ApplicationDBContext(DbContextOptions<ApplicationDBContext> options) : base(options)
{
}
public DbSet<Category> Categories { get; set; }
public DbSet<Product> Products { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Category>().HasData(
new Category() { Id=1, Name="Action", DisplayOrder = 1},
new Category() { Id = 2, Name = "SciFi", DisplayOrder = 2 },
new Category() { Id = 3, Name = "History", DisplayOrder = 3 }
);
modelBuilder.Entity<Product>().HasData(
new Product
{
Id = 1,
Title = "Fortune of Time",
Author = "Billy Spark",
Description = "Praesent ",
ISBN = "SWD9999001",
ListPrice = 99,
Price = 90,
Price50 = 85,
Price100 = 80
});
//base.OnModelCreating(modelBuilder);
}
}
}
And here is project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EntityFramework" Version="6.5.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..Bulky.ModelsBulky.Models.csproj" />
<ProjectReference Include="..Bulky.UtilityBulky.Utility.csproj" />
</ItemGroup>
</Project>
I tried:
enable-migrations -contexttypename Bulky.DataAccess.ApplicationDBContext
and I get:
The type ‘ApplicationDBContext’ does not inherit from DbContext. The DbMigrationsConfiguration.ContextType property must be set to a type that inherits from DbContext
I tried to find the answer without any result
Victor Bass is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.