Tuesday, July 30, 2019

One or more errors occurred. (Cannot create a DbSet for 'AppleSauce' because this type is not included in the model for the context.)'

At your implementation of Microsoft.EntityFrameworkCore.DbContext in your C# you will need to add your type to the OnModelCreating method as shown here to beat this "because this type is not included in the model for the context." problem when working with .NET Core's Database First Entity Framework approach.

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
   modelBuilder.Entity<AppleSauce>().ToTable("AppleSauce");
}

 
 

Note that the "AppleSauce" magic string does not have to correspond to the name of a database table. As best as I can tell it can be anything you like. It should not be the same across two line items in the OnModelCreating method however.

No comments:

Post a Comment