Entity Framework: Improving Performance when inserting a record in a table with many records

.net asp.net-web-api c# entity-framework-6 sql-server

Question

I want to insert a single record into a table with 60 columns (some of them are not required) and 2 million records. It takes about 20 seconds.

var package = new Package()
      {
          DestinationCityId = city.Id,
          OriginCityId = RequestDetails.User.Retailer.CityId,
          State = state,
          CreatedOn = RequestDetails.DateTime,
          CreatedByUserId = RequestDetails.User.Id,
          OrderedOn = RequestDetails.DateTime,
          CustomerName = "a",
          CustomerAddress = "a",
          CustomerEmail = "a",
          CustomerPostalCode = "a",
          CustomerLandPhone = "a",
          CustomerCellPhone = "aa",
          CustomerMessage = "a",
          CustomerSubstitute = "a",
          RetailerPackageDiscount = 0,
          Barcode = "2",
          InternalBarcode = "11111",
          PackagingWeight = 10,
          DeliveryType = PackageDeliveryType.ByPostExpress,
          ProvidedByWarehouse = false,
          NeedReview = false,
          NeedReviewType = NeedReviewType.Unknown,
          RetailerId = retailer.Id,
          Retailer = retailer
      };

DbContext.ZPackages.Add(package);
DbContext.SaveChanges();

Any Idea to improve performance?

1
1
2/19/2020 8:49:58 AM

Popular Answer

Partitions, Indexes, Async CRUD operations where it possible. This is not EF problem

2
2/19/2020 8:29:10 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow