我試圖複製在MSDN上找到的示例。我正在使用ASP.NET和EF 4.1(CTP?)。我已經使用NuGet來安裝EntityFramework軟件包。EF 4.1異常「提供程序沒有返回ProviderManifestToken字符串」
我得到這個錯誤:The provider did not return a ProviderManifestToken string
... 和數據庫永遠不會創建。
這裏是我的連接字符串:
<add name="HospitalContext"
connectionString=
"data source=.\SQLExpress;initial catalog=NewTestDB;integrated security=True;"
providerName="System.Data.SqlClient"/>
這裏是我的代碼:
var pat = new Patient { Name = "Shane123132524356436435234" };
db.Patients.Add(pat);
var labResult = new LabResult { Result = "bad", Patient = pat };
int recordAffected = db.SaveChanges();
這裏是我的背景:
public class HospitalContext : DbContext
{
static HospitalContext()
{
Database.SetInitializer(new HostpitalContextInitializer());
}
public DbSet<Patient> Patients { get; set; }
public DbSet<LabResult> LabResults { get; set; }
}
public class HostpitalContextInitializer :
DropCreateDatabaseIfModelChanges<HospitalContext>
{
protected override void Seed(HospitalContext context)
{
context.Patients.Add(new Patient { Name = "Fred Peters" });
context.Patients.Add(new Patient { Name = "John Smith" });
context.Patients.Add(new Patient { Name = "Karen Fredricks" });
}
}
這是一個完全使用補丁的SQL 2008系統,與VS 2010 SP1。
在向模型添加[Key]之後,它看起來似乎已經過去了這個問題。我仍然遇到另一個問題,但這可能解決了這個問題。 – bugnuker 2011-03-24 17:53:32
另外,它可能是我的連接字符串中添加了「Intergrated security = true」... – bugnuker 2011-03-24 19:17:20
我在處理'SqlServerCe.Entity.dll'時遇到了同樣的異常。 – 2011-07-02 07:37:16