我真的沒有每次EF的運氣。這一次,它看起來是這樣的:實體框架沒有創建表格
我第一次創造了一個方面,我有如下錯誤:
Invalid object name 'dbo.TableName1'
這個數據庫初始化器設置爲CreateDatabaseIfNotExists t將其做的伎倆後。
接下來我創建了一個不同的上下文,它在開發的某個時候發生了變化。所以這次我不斷收到此錯誤:
The model backing the 'NewContext' context has changed since the database was created.
我找到了解決設置數據庫初始化程序爲空,但在這之後我不斷收到的第一個錯誤:
Invalid object name 'dbo.TableName2'
我也試着設置在初始化到DropCreateDatabaseIfModelChanges和DropCreateDatabaseAlways,並且這些設置拋出異常:
Cannot drop database "DatbaseName" because it is currently in use
我想我已經嘗試過一切,我在網上找到(有沒有很多這類話題),但沒有人幫助我。
刪除數據庫並沒有幫助,也沒有從本地文件數據庫更改爲SQL Server 2014 Exspress。拋出同樣的異常。有任何想法嗎?
EDIT1: 工作方面:
public class ProfilesContext : DbContext
{
public ProfilesContext() : base("DefaultConnection")
{
}
public DbSet<Profile> Profiles { get; set; }
public DbSet<PrevilegedContact> PrevilegedContacts { get; set; }
}
失敗情境:
public class PlacesContext : DbContext
{
public PlacesContext()
: base("DefaultConnection")
{
}
public DbSet<Place> Places { get; set; }
public DbSet<Price> Prices { get; set; }
public DbSet<Photo> Photos { get; set; }
public DbSet<Comment> Comments { get; set; }
}
你可以顯示你的初始化代碼,你的DbContext類嗎? – James
用您請求的代碼編輯主題 –