我正在使用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();
}
但我收到错误指定的架构无效错误0064:Facet&#39; MaxLength&#39;不得为类型&#39; mediumtext&#39; 指定。所以如果我在这个过程中犯了任何错误,请指导。
这里我还有一个类
public class Tab2:Tab1
{
public string Filed3{get; set;}
}
我不想用tab2在数据库中创建表,因为我使用tab2类来返回自定义记录。我得到了上面的错误,因为Tab2继承自tab1,当我删除类tab2它像往常一样工作。所以请指导我。
答案 0 :(得分:0)
如果问题只是在模型中引入“Tab2”类时引起的,并且你真的不希望“Tab2”存储在数据库中,为什么不用它来注释“Tab2”类? [NotMapped]属性或使用流畅的配置ModelBuilder.Ignore。