I have one product table with consist of product number , price and currency. I upload the data through excel file with the data. When i upload the data then i create a list at back end with all data from excel and then send entire list to server to update/insert data in the table.
foreach(Product value in item)
{
Product p = context.Product.SingleOrDefault(p => p.ProductNumber == value.ProductNumber && p.CurrencyId == value.CurrencyId);
if (p!= null)
{
context.Entry<Product>(p).Property(p => p.ProductPrice).IsModified = true;
p.ProductPrice = value.ProductPrice ;
context.SaveChanges();
}
else
{
context.Product.Add(value);
context.SaveChanges();
}
}
But as the data increases (Product increase) then upload takes a lot of time. Any suggestion to optimize this? One stuff i am thinking is of Index on productnumber and currency column.