我放棄了。 我發現這個: http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-model-amp-database-first-walkthrough.aspx 並認爲,這很酷。 所以我很快重新設計了我的模型,以充分利用兩個世界中的最好的一個。模型首先用DbContext,未能初始化新的數據庫
但是現在我的模型在創建新的數據庫時失敗(或者將tabls添加到現有的數據庫中)。 我得到這個錯誤:
Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection string is specified in the config file of executing application. To use these classes, that were generated from Database First or Model First, with Code First add any additional configuration using attributes or the DbModelBuilder API and then remove the code that throws this exception.
在:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
這就是我的連接字符串:
<add name="ForumContextContainer"
providerName="System.Data.SqlClient"
connectionString="Data Source=.\SQLExpress; Initial Catalog=iForum; Integrated Security=True"/>
注意。我稍後添加了初始目錄,嘗試它是否能夠正常工作,但它完全一樣。
其實我通過chaning T4模板找到了一種方法。但是,無論如何, – 2011-05-09 22:24:12
@ŁukaszBaran很在意分享您的解決方案嗎? – 2011-07-28 20:25:22
@JoelBeckham我的問題是拋出新的UnintentionalCodeFirstException();在Entities類中。 – Saber 2012-02-14 09:12:23