简体   繁体   English

使用MVC控制器实体框架创建控制器时,显示“不受支持的上下文类型”。 MVC4

[英]“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. 因为每次我使用MVC控制器实体框架创建一个控制器。 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 DbSet属性需要嵌套在DbContext派生类中

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; }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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