asp.net-mvc - MVC 4 中的表属性无法识别

标签 asp.net-mvc entity-framework asp.net-mvc-4

我有一个如下所示的模型:

[Table("forms", Schema = "mySchema")]
public class forms
{
  [Key]
  public int ID { get; set; }
  public string field1 { get; set; }
  public string field2 { get; set; }
}

这在 MVC 3 中有效,但是在 MVC 4 中,属性表无法识别。我包含了 System.ComponentModel.DataAnnotations 命名空间,并引用了 dll 以及 EntityFramework.dll。 EF 的版本在 MVC 3 和 4 之间发生了变化。如果我引用 MVC 3 EF dll,则可以识别表,但不能识别架构。使用表属性的原因是这样我可以指定架构。我错过了什么?

最佳答案

根据msdn TableAttribute支持 schema 属性。

也许使用:

[Table(Name = "forms", Schema = "mySchema")]

关于asp.net-mvc - MVC 4 中的表属性无法识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12534331/

相关文章:

asp.net-mvc-4 - 使用 Kendo 对 ASP.NET MVC4 Controller 进行单元测试

c# - User.Identity.Name 返回 guid

c# - MVC4 模型验证然后使用 JQuery 将 JSON post 提交到外部 URI

c# - 如何在自定义 ModelBinder 中从 body 获取数据?

asp.net-mvc - MVC 模型有时需要字段

c# - 如何在 MVC 网页中重用模型或 DAL 和 BLL

c# - EF 中的 DbContext 是否应该具有较短的生命周期?

entity-framework - 为什么我的 DbContext DbSet 为空?

c# - ASP.NET MVC - 如何检测用户是否正在使用屏幕阅读器

sql-server - 请咨询: SQL Server Identity vs Unique Identifier keys when using Entity Framework