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?
There is a very useful Entity Framework Extension available at https://entityframework-extensions.net/
It is also available as a nuget package. 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
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".
This is a known issue when using e.g. entity-framework-6. As above @John S has already mentioned you can use extension libraries for bulk updates. 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, e.g. SQL Profiler.