0
아래 코드에서와 같이 10,000 행의 여러 행을 Entity Framework로 업데이트하기 위해 ADO.Net을 테이블 값 매개 변수 코드로 변환하기로 결정했습니다. 아래의 결과는 ADO.Net TVP가 1 초 미만인 반면 Entity Framework는 2 분 34 초가 걸린 것을 보여줍니다. 이제 내 질문은 내 Entity Framework 코드를 TVP 코드가있는 ADO.Net처럼 빠르게 실행하는 방법입니다.Entity Framework vs ADO.Net with TVP 다중 행 업데이트
[Table("Employee")]
public class Employee
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int EmployeeId { get; set; }
public string FirstName { get; set; }
public string Lastname { get; set; }
public string Town { get; set; }
public string PostCode { get; set; }
}
public class EmployeeContext : DbContext
{
public DbSet<Employee> Employees { get; set; }
}
class Program
{
static void Main(string[] args)
{
List<Employee> employees = new List<Employee>();
Stopwatch stopwatch = Stopwatch.StartNew();
for (int i = 1; i <= 10000; i++)
{
Employee emp = new Employee();
emp.EmployeeId = i;
emp.FirstName = "FirstName" + i;
emp.Lastname = "Lastname" + i;
emp.Town = "Town" + i;
emp.PostCode = "PostCode" + i;
employees.Add(emp);
}
var e = employees.OrderBy(o => Convert.ToInt32(o.EmployeeId)).ToList();
SaveEmployeeToDatabase(e, "EmployeeDB");
stopwatch.Stop();
string t = stopwatch.Elapsed.ToString();
Console.WriteLine("Time Elapse: " + t + ": " + "ADO.Net Update Multiple Rows with TVP");
/*Entity Entity Framework Update Multiple Rows*/
EmployeeContext db = new EmployeeContext();
Stopwatch stopwatch1 = Stopwatch.StartNew();
for (int i = 1; i <= 10000; i++)
{
Employee emp1 = new Employee();
emp1.EmployeeId = i;
emp1.FirstName = "NewFirstName" + i;
emp1.Lastname = "NewLastname" + i;
emp1.Town = "NewTown" + i;
emp1.PostCode = "NewPostCode" + i;
db.Employees.Add(emp1);
db.Entry(emp1).State = EntityState.Modified;
}
db.SaveChanges();
stopwatch1.Stop();
string t1 = stopwatch1.Elapsed.ToString();
Console.WriteLine("Time Elapse: " + t1 + ": " + "Entity Framework Update Multiple Rows");
Console.Read();
}
답장을 보내 주신 David 께 감사드립니다. – CodingSoft