我使用WAF(WPF應用程序框架):https://waf.codeplex.com。 我打開BookLibrary項目中的示例。 我有一個名爲Author和它相關的類的模型。WAF(WPF應用程序框架)在這裏添加新的實體表
,這是它的DbContext:..
internal class BookLibraryContext : DbContext
{
public BookLibraryContext(DbConnection dbConnection)
: base(dbConnection, false)
{
Database.SetInitializer<BookLibraryContext>(null);
}
public BookLibraryContext()
: base(@"Data Source=|DataDirectory|\Resources\BookLibrary2.sdf")
{
}
public bool HasChanges
{
get
{
ChangeTracker.DetectChanges();
// It is necessary to ask the ObjectContext if changes could be detected because the
// DbContext does not provide the information when a navigation property has changed.
return ObjectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Any()
|| ObjectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Modified).Any()
|| ObjectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Deleted).Any();
}
}
private ObjectContext ObjectContext { get { return ((IObjectContextAdapter)this).ObjectContext; } }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Configurations.Add(new PersonMapping());
modelBuilder.Configurations.Add(new BookMapping());
modelBuilder.Configurations.Add(new AuthorMapping());
}
}
當我運行該項目。發生異常:
{"The specified table does not exist. [ Author ]"}
如何添加名爲Author的新表?我知道使用Entity Framework遷移或使用工具編輯數據庫結構。
但我看到一個名爲HasChange()的方法。它可能會做一些事情來反映我的數據庫。但我不知道要做到這一點。請幫我
http://stackoverflow.com/questions/2375118/how-to-open-sdf-files您可能需要打開數據庫BookLibrary2.sdf添加表。 – ray