1

我正在对大约 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; }
}
4

0 回答 0