SqlException (0x80131904): 無效的物件名稱 dbo



自己筆記紀錄一下…

EF會在資料表名稱後面自動加上S,但要指定資料表的話需要用到 OnModelCreating



解決方案:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    base.OnModelCreating(modelBuilder);
    modelBuilder.Entity<User>().ToTable("User");
}



參考文獻:
https://stackoverflow.com/questions/5374482/sqlexception-0x80131904-invalid-object-name-dbo-categories

Leave a Reply