[英]Entity Framework: Improving Performance when inserting a record in a table with many records
I want to insert a single record into a table with 60 columns (some of them are not required) and 2 million records.我想在一个有 60 列(其中一些不是必需的)和 200 万条记录的表中插入一条记录。 It takes about 20 seconds.
大约需要 20 秒。
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?任何想法来提高性能?
Partitions , Indexes , Async CRUD operations where it possible. 分区、 索引、异步 CRUD操作尽可能。 This is not EF problem
这不是EF问题
如果您使用的是 EF Core,您还可以查看 EfCore Bulk Extensions 项目https://github.com/borisdj/EFCore.BulkExtensions
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.