简体   繁体   English

如何在较短的时间内使用实体框架同时编辑1000条记录

[英]How to edit 1000 records at time using entity framework in less time

public ActionResult EditRow()
{
        using (SchoolContext db = new SchoolContext())
        {
            var v = db.Students.ToList();
            return View(v);
        }
}

[HttpPost]
public ActionResult EditRow(List<Student> student)
{
        if (ModelState.IsValid)
        {
            using (SchoolContext db = new SchoolContext())
            {
                foreach (var i in student)
                {
                    var c = db.Students.Where(a => a.ID.Equals(i.ID)).FirstOrDefault();
                    if (c != null)
                    {
                        c.LastName = i.LastName;
                        c.FirstMidName = i.FirstMidName;
                        c.EnrollmentDate = i.EnrollmentDate;
                    }
                }
                db.SaveChanges();
                return RedirectToAction("Index");

            }
            ViewBag.Message = "Successfully updated";
            return View(student);

        }
        else
        {
            ViewBag.Message = "failed";
            return View(student);
}

Right now I have implemented this code,but server takes more time to edit records. 现在,我已经实现了此代码,但是服务器需要更多时间来编辑记录。 Is there any way to edit records quickly? 有什么办法可以快速编辑记录? How can I minimise Execution time? 如何最小化执行时间? and how to check time complexity in Visual studio? 以及如何检查Visual Studio中的时间复杂度?

There is a very useful Entity Framework Extension available at https://entityframework-extensions.net/ https://entityframework-extensions.net/上有一个非常有用的Entity Framework Extension。

It is also available as a nuget package. 它也可以作为nuget包提供。 This extension gives you bulk updates and inserts and works very well. 此扩展为您提供批量更新和插入,并且效果很好。

The nuget package can be installed with this command from the package manager window Install-Package Z.EntityFramework.Extensions 可以从软件包管理器窗口Install-Package Z.EntityFramework.Extensions使用此命令Install-Package Z.EntityFramework.Extensions

The above packages appears to be a commercial package now but I know there are some similar extension libraries out there that do the same thing. 上面的软件包现在看来是一个商业软件包,但是我知道那里有一些类似的扩展库也可以做同样的事情。

I would remark this question as already answered. 我认为这个问题已经回答。 There are a lot of stated answers how-to-do, if you searching for keywords like "ef bulk updates". 如果您搜索“ ef批量更新”之类的关键字,则有很多明确的答案。

This is a known issue when using eg entity-framework-6. 当使用例如entity-framework-6时,这是一个已知问题。 As above @John S has already mentioned you can use extension libraries for bulk updates. 如上所述,@ John S已经提到您可以使用扩展库进行批量更新。 I am not sure what you mean with "time complexity" in that context. 在这种情况下,我不确定您所说的“时间复杂性”是什么意思。 If you use an OR mapper, you should profile your SQL statements anyway, eg SQL Profiler . 如果使用OR映射器,则无论如何都应配置SQL语句, 例如SQL Profiler

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取实体框架中特定时间之间的记录 - how to get the records between specific time in entity framework 如何在实体框架中使用linq查询获取特定时间之间的记录 - how to get records between particular time using linq query in entity framework 如何使用Entity Framework按创建日期升序删除1000条记录? - How to delete 1000 records based upon created date ascending using Entity Framework? 首次获取记录时,如何在UIusing Entity Framework 6上显示消息(已加载1000个项目中的50个)? - How to show the message (50 of 1000 items loaded) on the UIusing Entity Framework 6 when record is fetched for the first time? 如何在ASP.NET MVC中使用实体框架更新/编辑多个记录 - How to Update/Edit multiple records using Entity Framework in ASP.NET MVC 如何使用Entity Framework同时保存到数据库的2个表 - How to save to 2 tables of a database at the same time using Entity Framework 如何使用实体框架一次将数据插入两个表中 - how to insert data into two tables at a time using entity framework C#,实体框架,如何同时更新(删除、添加、编辑)多行? - C#, Entity Framework, How to Update(delete, add, edit) multiple rows at same time? 如何使用实体框架编辑值? - How to edit a value using Entity Framework? 实体框架时间问题 - Entity Framework Time Issue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM