为新建项目开启一个(asp.net mvc5单页程序)EF的codefirst测试,代码如下:
var en = new Enterprise
{
name = "企业",
address ="地址",
legalPerson ="法人名字",
contactName = "联系人名字",
contactTel = "联系人电话",
contactPhone = "联系人手机",
createTime = DateTime.Now.Date,
longitude = 111.22f,
latitude=23.23f
};
try
{
Database.SetInitializer<MyContext>(new DropCreateDatabaseIfModelChanges<MyContext>());
using (var context = new MyContext())
{
context.enterprises.Add(en);
context.SaveChanges();
}
}
catch (Exception e)
{
Assert.AreEqual("ok", e.Message);
}
显示测试成功却在数据库找不到建立的表示怎么回事?
测试的app.config连接串已经配置成和工程web.config一样
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(Local);Initial Catalog=mydb;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>