add this package in nuget
EF6
PM> Install-Package EntityFramework.BulkInsert-ef6
https://www.nuget.org/packages/EntityFramework.BulkInsert-ef6
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Transactions;
using EntityFramework.BulkInsert.Extensions;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
using (DatabaseEntities de=new DatabaseEntities())
{
using (TransactionScope ts = new TransactionScope())
{
List<EMP> lst = new List<EMP>();
EMP emp = new EMP();
emp.EID = 1;
emp.NAME = "siv";
lst.Add(emp);
EMP emp1 = new EMP();
emp1.EID = 2;
emp1.NAME = "sankar";
lst.Add(emp1);
EMP emp2 = new EMP();
emp2.EID = 3;
emp2.NAME = "mahadev";
lst.Add(emp2);
de.BulkInsert(lst, batchSize:null);
de.SaveChanges();
ts.Complete();
}
}
}
}
}
EF6
PM> Install-Package EntityFramework.BulkInsert-ef6
https://www.nuget.org/packages/EntityFramework.BulkInsert-ef6
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Transactions;
using EntityFramework.BulkInsert.Extensions;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
using (DatabaseEntities de=new DatabaseEntities())
{
using (TransactionScope ts = new TransactionScope())
{
List<EMP> lst = new List<EMP>();
EMP emp = new EMP();
emp.EID = 1;
emp.NAME = "siv";
lst.Add(emp);
EMP emp1 = new EMP();
emp1.EID = 2;
emp1.NAME = "sankar";
lst.Add(emp1);
EMP emp2 = new EMP();
emp2.EID = 3;
emp2.NAME = "mahadev";
lst.Add(emp2);
de.BulkInsert(lst, batchSize:null);
de.SaveChanges();
ts.Complete();
}
}
}
}
}
No comments:
Post a Comment