I'm developing application with c#.net entity framework and sql server 2008r2. Here is my code
C#.net Code
foreach (var tempProduct in purchaseDetailTemp)
{
invPurchase = new InvPurchaseDetailTemp();
invPurchase.ProductID = tempProduct.InvProductMasterID;
invPurchase.ProductCode = tempProduct.ProductCode;
invPurchase.ProductName = tempProduct.ProductName;
context.InvPurchaseDetails.Add(invPurchase);
context.SaveChanges();
}
purchaseDetailTemp is my datatable. I want to save data without foreach
loop. I'm trying this with mergeSql and bulk insert. Is there a way to do that?
context.SaveChanges();
out of theforeach
loop?