简体   繁体   中英

“Unsupported context type” while creating a controller using MVC controller Entity Framework. MVC4

Here is my code (Model);

  public class XpsEntity
  {
    public DbSet<AModel> A { get; set; }
    public DbSet<TModel> T { get; set; }

    public class SDbContext : DbContext
    {
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<XpsEntity>().ToTable("Table1");
            modelBuilder.Entity<XpsEntity>().ToTable("Table2");

        }
    }

Is my coding wrong? Because every time I create a controller using MVC Controller Entity Framework. I always get the "Unsupported context type" error.

Here is the screenshot for adding the controller.

DbSet properties need to be nested in a DbContext derived class

public class SDbContext : DbContext {
    protected override void OnModelCreating(DbModelBuilder modelBuilder) {
        modelBuilder.Entity<AModel>().ToTable("Table1");
        modelBuilder.Entity<TModel>().ToTable("Table2");
    }

    public DbSet<AModel> A { get; set; }
    public DbSet<TModel> T { get; set; }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM