Code generator error: object type is missing in DbContext

I want to create a simple ASP.NET Core application. But when I try to create an API controller for my model, I get the following error: (Screen shots represent the code for the model class and db context, below is the code for the EntityBase class)

Setting forest properties for codes

Error

public abstract class EntityBase { [Key] public int Id { get; set; } public DateTime Modified { get; set; } public DateTime Created { get; set; } public EntityBase() { Created = DateTime.Now; Modified = Created; } } 
+6
source share
4 answers

Ok, so I found the reason for this error. I created a Many to Many relationship between Convent and Group without using a third class. I used a quick api for this.

Thank you all for your help!

0
source

Having the same problem as the name mentioned, but without any problem with the key or connection, I finally found a solution to this problem. In particular, using forest controllers / representations from model classes created using a database-based approach. In your DbContext class, you MUST HAVE a class constructor that accepts the DbContextOptions<MyDb> parameter, which for some reason is not added using the "Scaffold-DbContext" command in the package manager console (with an ASPNETCORE project)

 public partial class MyDbContext : DbContext { public MyDbContext(DbContextOptions<MyDbContext> options) : base(options) { } public virtual DbSet<MyModel> MyModel { get; set; } } 

For others, there should also be a connection string in the appsettings.json file and the following code in the ConfigureServies method of the startup.cs add file:

 se‌​rvices.AddDbContext<‌​MyDbContext>(opt‌​ions => options.UseSqlServer(Configuration.GetConnectionString("MyDbContection"))); 
+1
source

Adding the [Key] property solves the problem when there are no Many to Many links and no PRIMARY KEYs in the classes

0
source

In my case, the reason was calling dbContext.Database.Migrate() inside Startup.Configure() . The error disappeared when I deleted it.

-one
source

All Articles