andreisabau / efbulkinsert Goto Github PK
View Code? Open in Web Editor NEWExtension method over the Entity Framework DbContext for bulk insertion of entities.
Home Page: https://www.nuget.org/packages/EFBulkInsert/
License: MIT License
Extension method over the Entity Framework DbContext for bulk insertion of entities.
Home Page: https://www.nuget.org/packages/EFBulkInsert/
License: MIT License
Do you have any plans on supporting related entities?
when insert using efbulkinsert it thows SQL Exception Invalid Column Name . Table has identity column as well. Only different thing is that table has schema instead of (dbo.tablename). Is that the issue or it is something else? Insert was fine when table had dbo. schema
When I tried to insert about 1 500 000 records I have got an error.
System.AggregateException: One or more errors occurred. ---> System.Data.SqlClient.SqlException: Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception: The wait operation timed out --- End of inner exception stack trace --- at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TrySetMetaData(_SqlMetaDataSet metaData, Boolean moreInfo)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) at EFBulkInsert.BulkInsertExtension.MergeDataIntoOriginalTable(DbContext dbContext, EntityMetadata entityMetadata, Int32 startIndex) in D:\temp\0cf0aa1\EFBulkInsert\BulkInsertExtension.cs:line 110 at EFBulkInsert.BulkInsertExtension.BulkInsert[T](DbContext dbContext, IEnumerable
1 entites, Int32 batchSize) in D:\temp\0cf0aa1\EFBulkInsert\BulkInsertExtension.cs:line 34`
For example, my table is named "Summaries" and the model is named Summary. It is attempting to insert into Summary which does not exist.
SqlBulkCopy should be aware if an existing transaction exists and use the proper constructor.
Running Entity Framework 6.2.0 here, and getting syntax error when using the extension method.
Here's the exception:
System.Data.SqlClient.SqlException occurred
HResult=0x80131904
Message=Incorrect syntax near ';'.
Source=.Net SqlClient Data Provider
StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at EFBulkInsert.BulkInsertExtension.MergeDataIntoOriginalTable(DbContext dbContext, EntityMetadata entityMetadata, Int32 startIndex)
at EFBulkInsert.BulkInsertExtension.BulkInsert[T](DbContext dbContext, IEnumerable`1 entites, Int32 batchSize)
at Project.Data.Core.Repositories.Repository`1.BulkInsert(IEnumerable`1 toAdd, Int32 batchSize) in C:\ProjectFolder\Data\Core\Repositories\Repository.cs:line 84
at FakeModels.DBSeeder.Seed() in C:\ProjectFolder\FakeModels\DBSeeder.cs:line 115
at Project.Program.Main(String[] args) in C:\ProjectFolder\Project\Program.cs:line 23
Here's the last run Query, found on SQL Server Profiler 17:
MERGE INTO CatalogueLineItem AS DestinationTable
USING (SELECT * FROM ##TEMP_3e4c2877_9705_4b67_8dfa_5a77bf67d6e1 WHERE ArrayIndex >= 0) AS TempTable
ON 1 = 2
WHEN NOT MATCHED THEN INSERT ([CatalogueId],[LineId],[ActionCode],[LifecycleStatusCode],[Note],[Orderable],[OrderableUnit],[ContentUnitQuantity],[OrderQuantityIncrementNumeric],[MinimumOrderQuantity],[MaximumOrderQuantity],[SellerSupplierCustomerAssignedId],[SellerSupplierAdditionalId],[SellerSupplierPartyIdType],[SellerSupplierPartyId],[SellerSupplierPartyName],[LineValidityStartDate],[LineValidityStartTime],[LineValidityEndDate],[LineValidityEndTime],[LeadTimeUnit],[LeadTimeMeasure],[PriceMinimumQuantity],[PriceMaximumQuantity],[PriceAmountCurrency],[PriceAmount],[PriceBaseQuantityUnit],[PriceBaseQuantity],[PriceOrderableUnitFactorRate],[AllowanceChargeIndicator],[AllowanceChargeReasonCode],[AllowanceChargeReason],[AllowanceChargeMultiplierFactorNumeric],[AllowanceChargePrepaidIndicator],[AllowanceChargeAmount],[AllowanceChargeBaseAmount],[DeliveryUnitBatchQuantityUnit],[DeliveryUnitBatchQuantity],[DeliveryUnitConsumerQuantityUnit],[DeliveryUnitConsumerQuantity],[TaxCategoryId],[TaxCategoryName],[TaxCategoryPercent],[TaxCategoryBaseUnit],[TaxPerUnitAmount],[TaxExemptionReasonCode],[TaxExemptionReason],[TaxSchemeId],[TaxSchemeName],[TaxSchemeTypeListId],[TaxSchemeListAgencyId],[TaxSchemeListAgencyName],[TaxScheme],[TaxCurrencyCode],[ItemDescription],[PackQuantity],[PackSize],[ItemName],[HazardousRiskIndicator],[AdditionalInformation],[Keywords],[BrandName],[ModelName],[BuyersItemId],[SellersItemId],[ManufacturersItemId],[StandardItemId],[CatalogueItemId],[AdditionalItemId],[CommodityClassificationListName],[CommodityClassificationListVersion],[CommodityClassificationCode],[ManufacturerPartyIdType],[ManufacturerPartyId],[ManufacturerPartyName],[OriginAddressCountryId],[OriginAddressCountryName],[IsOsdItem],[PackLevel1Unit],[PackLevel1Quantity],[PackLevel1Ean],[PackLevel1Width],[PackLevel1Height],[PackLevel1Length],[PackLevel1GrossWeight],[PackLevel2Unit],[PackLevel2Quantity],[PackLevel2Ean],[PackLevel2Width],[PackLevel2Height],[PackLevel2Length],[PackLevel2GrossWeight],[PackLevel3Unit],[PackLevel3Quantity],[PackLevel3Ean],[PackLevel3Width],[PackLevel3Height],[PackLevel3Length],[PackLevel3GrossWeight],[PackLevel4Unit],[PackLevel4Quantity],[PackLevel4Ean],[PackLevel4Width],[PackLevel4Height],[PackLevel4Length],[PackLevel4GrossWeight],[PackLevelPalletUnit],[PackLevelPalletQuantity],[PackLevelPalletEan],[PackLevelPalletWidth],[PackLevelPalletHeight],[PackLevelPalletLength],[PackLevelPalletGrossWeight]) VALUES
([CatalogueId],[LineId],[ActionCode],[LifecycleStatusCode],[Note],[Orderable],[OrderableUnit],[ContentUnitQuantity],[OrderQuantityIncrementNumeric],[MinimumOrderQuantity],[MaximumOrderQuantity],[SellerSupplierCustomerAssignedId],[SellerSupplierAdditionalId],[SellerSupplierPartyIdType],[SellerSupplierPartyId],[SellerSupplierPartyName],[LineValidityStartDate],[LineValidityStartTime],[LineValidityEndDate],[LineValidityEndTime],[LeadTimeUnit],[LeadTimeMeasure],[PriceMinimumQuantity],[PriceMaximumQuantity],[PriceAmountCurrency],[PriceAmount],[PriceBaseQuantityUnit],[PriceBaseQuantity],[PriceOrderableUnitFactorRate],[AllowanceChargeIndicator],[AllowanceChargeReasonCode],[AllowanceChargeReason],[AllowanceChargeMultiplierFactorNumeric],[AllowanceChargePrepaidIndicator],[AllowanceChargeAmount],[AllowanceChargeBaseAmount],[DeliveryUnitBatchQuantityUnit],[DeliveryUnitBatchQuantity],[DeliveryUnitConsumerQuantityUnit],[DeliveryUnitConsumerQuantity],[TaxCategoryId],[TaxCategoryName],[TaxCategoryPercent],[TaxCategoryBaseUnit],[TaxPerUnitAmount],[TaxExemptionReasonCode],[TaxExemptionReason],[TaxSchemeId],[TaxSchemeName],[TaxSchemeTypeListId],[TaxSchemeListAgencyId],[TaxSchemeListAgencyName],[TaxScheme],[TaxCurrencyCode],[ItemDescription],[PackQuantity],[PackSize],[ItemName],[HazardousRiskIndicator],[AdditionalInformation],[Keywords],[BrandName],[ModelName],[BuyersItemId],[SellersItemId],[ManufacturersItemId],[StandardItemId],[CatalogueItemId],[AdditionalItemId],[CommodityClassificationListName],[CommodityClassificationListVersion],[CommodityClassificationCode],[ManufacturerPartyIdType],[ManufacturerPartyId],[ManufacturerPartyName],[OriginAddressCountryId],[OriginAddressCountryName],[IsOsdItem],[PackLevel1Unit],[PackLevel1Quantity],[PackLevel1Ean],[PackLevel1Width],[PackLevel1Height],[PackLevel1Length],[PackLevel1GrossWeight],[PackLevel2Unit],[PackLevel2Quantity],[PackLevel2Ean],[PackLevel2Width],[PackLevel2Height],[PackLevel2Length],[PackLevel2GrossWeight],[PackLevel3Unit],[PackLevel3Quantity],[PackLevel3Ean],[PackLevel3Width],[PackLevel3Height],[PackLevel3Length],[PackLevel3GrossWeight],[PackLevel4Unit],[PackLevel4Quantity],[PackLevel4Ean],[PackLevel4Width],[PackLevel4Height],[PackLevel4Length],[PackLevel4GrossWeight],[PackLevelPalletUnit],[PackLevelPalletQuantity],[PackLevelPalletEan],[PackLevelPalletWidth],[PackLevelPalletHeight],[PackLevelPalletLength],[PackLevelPalletGrossWeight])
OUTPUT TempTable.ArrayIndex, ;
Please let me know if you need more information.
Hi,
When trying to upgrade my nuget package to v0.5.0 I receive the error message below.
Could not install package 'EFBulkInsert 0.5.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.8', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
Could the package target .NET framework 4.8 please?
Thanks!
I'm trying to insert 5000+ rows from a datatable to SQL server Database.
Every time i invoke db.BulkInsert(resList); error message is the one mentioned in object.
(db is my context name, and resList is a List of entity i wanted to insert).
My Primary Key is generated through my code and might be inserted that way with all the rows.
Can you please help !!!
Thanks in advance
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.