我正在对数据库表进行一些简单的保存,大约有20列,需要20秒。检索记录几乎是即时的。我不确定为什么会这样。有什么我做错了或有更快的方法吗?
db.Entry(EmInf).State = System.Data.EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Confirm/");
(MVC 4& SQL 2008 R2 |我应该注意,其他网站能够以更快的速度更新数据,但它们是旧程序并且不使用EF。这是EF的性能问题吗?我不明白为什么,因为我所做的其他MVC程序似乎没有这个问题。)
更新:这是数据库首次设置。忘了提。
以下是完整的方法:
[HttpPost]
[Authorize]
public ActionResult Edit(Em_Emergency_Info EmInf)
{
try
{
using (var db = new WINDEntities()) {
db.Entry(EmInf).State = System.Data.EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Confirm/");
}
}
catch (DbEntityValidationException dbEx)
{
foreach (var validationErrors in dbEx.EntityValidationErrors)
{
foreach (var validationError in validationErrors.ValidationErrors)
{
Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
}
}
int rec = Convert.ToInt32(User.Identity.Name);
return View(db.Em_Emergency_Info.Find(rec));
}
}
以下是模型:
using System;
using System.Collections.Generic;
public partial class Em_Emergency_Info
{
public int id { get; set; } //This is the primary key.
public string Em_PIn_Key { get; set; }
public string Em_policy_nb { get; set; }
public string Em_Pin_nb { get; set; }
public string Em_First_Name { get; set; }
public string Em_Last_Name { get; set; }
public string Em_Addr1 { get; set; }
public string Em_Addr2 { get; set; }
public string Em_City { get; set; }
public string Em_State { get; set; }
public string Em_Zip { get; set; }
public string Em_Plus4 { get; set; }
public string Em_Phone_Home { get; set; }
public string Em_Phone_Work { get; set; }
public string Em_Mobile { get; set; }
public string Em_Email { get; set; }
public string Em_Fax_Nb { get; set; }
public string Em_Relationship { get; set; }
public string Em_type { get; set; }
public bool EmailOptIn { get; set; }
public bool PhoneOptIn { get; set; }
public bool PushOptIn { get; set; }
public bool FaxOptIn { get; set; }
public string Em_Mobile2 { get; set; }
public string Em_EMail2 { get; set; }
public string Em_Other_Info { get; set; }
public string Em_Primary_Contact { get; set; }
public string Em_Full_Name { get; set; }
}