0

我正在研究 asp.net mvc 4 web api。我首先使用现有数据库模型的代码。我的数据库中有一个表,所以我有像这样的实体类,

public class Tab1
{
[Key]
public int Field1{get; set;}
public string Field2{get; set;}
}

我有 DBContext 文件,例如,

public class MyDBContext:DbContext
{
public DbSet<Tab1> Table{ get; set; }

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
           modelBuilder.Entity<Bar>().ToTable("bars");
        }
}

我的 Get Action 就像

 public List<Bar> GetTables()
            {
               MyDBContext context=new MyDBContext();
                return context.Table.ToList();
            }

但是我收到一个错误Schema specified is not valid 错误 0064: Facet 'MaxLength' must not be specified for type 'mediumtext'。. 所以如果我在这个过程中犯了任何错误,请指导。

在这里,我还有一堂课,例如

public class Tab2:Tab1
{
public string Filed3{get; set;}
}

我不想使用 tab2 在数据库中创建表,因为我使用 tab2 类来返回自定义记录。由于 Tab2 从 tab1 继承,当我删除类 tab2 时,我得到了上述错误,它照常工作。所以请指导我。

4

1 回答 1

0

如果您的问题仅是在模型中引入“Tab2”类时引起的,并且您真的不希望将“Tab2”存储在数据库中,为什么不使用 [NotMapped] 注释“Tab2”类属性或使用流畅的配置 ModelBuilder.Ignore。

于 2013-03-01T23:29:00.943 回答