![](/img/trans.png)
[英]Entity Framework Code First naming conventions - back to plural table names?
[英]Entity Framework Code First table naming issue, singular confilcts with Plural
我有2個要在MVC中嘗試訪問的表,一個表稱為“員工”,一個表稱為“負責”。 這是我的代碼:-
public class dbEntity: DbContext
{
public dbEntity(): base("name=dbEntity") {}
public DbSet<Accountable> Accountable { get; set; }
public DbSet<Employees> Employees { get; set; }
}
問題是代碼抱怨它找不到表“ Accountables”,我知道我可以添加以下行:-
protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); }
但是隨后代碼抱怨它找不到'Employee'。 目前,重命名表是不現實的,還有另一種方法嗎?
謝謝
將數據庫中表名的數據注釋添加到上下文類。
[Table("TableName")]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.