我正在尝试复制在MSDN上找到的示例。我正在使用ASP.NET和EF 4.1(CTP?)。我已经使用NuGet来安装EntityFramework软件包。
我收到此错误: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" });
}
}
这是带有VS 2010 SP1的完全修补的SQL 2008系统。