我一直盯着这个,直到我看不清。我有一个控制台应用程序,用于在将其转换为服务之前测试逻辑。从网络应用程序触发时,相同的代码工作正常学生对象被很好地填充并且它没有抛出任何错误,但它从不保存到数据库中。对我到底想念什么有任何见解吗?
我的 app.config 文件有连接字符串
<connectionStrings>
<add name="DatabaseContext" connectionString="Data Source=|DataDirectory|Development.sdf" providerName="System.Data.SqlServerCe.4.0" />
<add name="DevelopmentEntities" connectionString="metadata=res://*/EntityModel.csdl|res://*/EntityModel.ssdl|res://*/EntityModel.msl;provider=System.Data.SqlServerCe.4.0;provider connection string="Data Source=|DataDirectory|\Development.sdf"" providerName="System.Data.EntityClient" />
</connectionStrings>
foreach (DataRow dr in dt.Rows)
{
//fill student object and add to list
Student s = new Student();
s.SID = dr[0].ToString();
s.FirstName = dr[1].ToString();
s.LastName = dr[2].ToString();
if (sctType == "TRAD")
{ s.Type = Convert.ToInt32(UniversityGateway.Data.Models.StudentType.Traditional); }
else
{ s.Type = Convert.ToInt32(UniversityGateway.Data.Models.StudentType.AGS); }
s.Email = dr[5].ToString();
s.Address = new Address
{
Street = dr[6].ToString(),
City = dr[9].ToString(),
State = dr[10].ToString(),
Zip = dr[11].ToString(),
};
s.UserActive = "Y";
s.Status = Convert.ToInt32(UniversityGateway.Data.Models.StudentStatus.Pending);
s.Password = "kHPrSps3JnTkmky7PakBZg==Wdc9Qgcz39p+s6+fqk/nUw==";
students.Add(s);
using (var db = new UniversityGateway.Data.DatabaseContext())
{
db.Students.Add(s);
db.SaveChanges();
}
}