EFCore.BulkExtensions
8.1.2
dotnet add package EFCore.BulkExtensions --version 8.1.2
NuGet\Install-Package EFCore.BulkExtensions -Version 8.1.2
<PackageReference Include="EFCore.BulkExtensions" Version="8.1.2" />
paket add EFCore.BulkExtensions --version 8.1.2
#r "nuget: EFCore.BulkExtensions, 8.1.2"
// Install EFCore.BulkExtensions as a Cake Addin #addin nuget:?package=EFCore.BulkExtensions&version=8.1.2 // Install EFCore.BulkExtensions as a Cake Tool #tool nuget:?package=EFCore.BulkExtensions&version=8.1.2
EFCore.BulkExtensions
EntityFrameworkCore extensions (performance improvement - into overdrive):
-Bulk operations (super fast): Insert, Update, Delete, Read, Upsert, Sync, SaveChanges.
-Batch ops: Update, Delete - Deprecated from EF8 since EF7+ has native Execute-Up/Del.
-AddOps (additional): Truncate.
Library is Lightweight and very Efficient (warp speed), having all mostly used CRUD operation.
Was selected in top 20 EF Core Extensions recommended by Microsoft.
Latest version is using EF Core 8.
Supports all 4 major sql databases: SQLServer, PostgreSQL, MySQL, SQLite.
Check out Testimonials from the Community and User Comments.
Icon>> and Logo (__):
<img src="/EFCore.BulkExtensions/EFCoreBulk.png" height=60> & <img src="EFCoreBulkLogo_small.png" height=60>
(f.forward | rocket time)
*Also take a look into others packages:</br> Open source (MIT or cFOSS) authored .Net libraries (@Infopedia.io personal blog post) | № | .Net library | Description | | - | ------------------------ | -------------------------------------------------------- | | 1 | EFCore.BulkExtensions | EF Core Bulk CRUD Ops (Flagship Lib) | | 2 | EFCore.UtilExtensions | EF Core Custom Annotations and AuditInfo | | 3 | EFCore.FluentApiToAnnotation | Converting FluentApi configuration to Annotations | | 4 | FixedWidthParserWriter | Reading & Writing fixed-width/flat data files | | 5 | CsCodeGenerator | C# code generation based on Classes and elements | | 6 | CsCodeExample | Examples of C# code in form of a simple tutorial |
License
BulkExtensions licensed under Dual License v1.0 (cFOSS: conditionallyFree OSS as a solution to OpenSource funding).
If you do not meet criteria for free usage of software with community license then you have to buy commercial one.
If eligible for free usage but still need active support, consider purchasing Starter Lic.
Support
If you find this project useful you can mark it by leaving a Github Star ⭐
And even with community license, if you want help development, you can make a DONATION:
<img src="https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png" alt="Buy Me A Coffee" height=28> _ or _
:zap:
Contributing
Please read CONTRIBUTING for details on code of conduct, and the process for submitting pull requests.
When opening issues do write detailed explanation of the problem or feature with reproducible example.
Want to Contact for Development & Consulting: www.codis.tech (Quality Delivery)
Description
Supported databases:
-SQLServer (or AzureSQL) under the hood uses SqlBulkCopy for Insert, Update/Delete = BulkInsert + raw Sql MERGE.
-PostgreSQL (9.5+) is using COPY BINARY combined with ON CONFLICT for Update.
-MySQL (8+) is using MySqlBulkCopy combined with ON DUPLICATE for Update.
-SQLite has no Copy tool, instead library uses plain SQL combined with UPSERT.
Bulk Tests can not have UseInMemoryDb because InMemoryProvider does not support Relational-specific methods.
Instead Test options are SqlServer(Developer or Express), LocalDb(if alongside Developer v.), or with other adapters.
Installation
Available on
That is main nuget for all Databases, there are also specific ones with single provider for those who need small packages.
Package manager console command for installation: Install-Package EFCore.BulkExtensions
Specific ones have adapter suffix: MainNuget + .SqlServer/PostgreSql/MySql/Sqlite
(
)
Its assembly is Strong-Named and Signed with a key.
| Nuget | Target | Used EF v.| For projects targeting |
| ----- | --------------- | --------- | ------------------------------- |
| 8.x | Net 8.0 | EF Core 8 | Net 8.0+ |
| 7.x | Net 6.0 | EF Core 7 | Net 7.0+ or 6.0+ |
| 6.x | Net 6.0 | EF Core 6 | Net 6.0+ |
| 5.x | NetStandard 2.1 | EF Core 5 | Net 5.0+ |
| 3.x | NetStandard 2.0 | EF Core 3 | NetCore(3.0+) or NetFrm(4.6.1+) info|
| 2.x | NetStandard 2.0 | EF Core 2 | NetCore(2.0+) or NetFrm(4.6.1+) |
| 1.x | NetStandard 1.4 | EF Core 1 | NetCore(1.0+) |
Supports follows official .Net lifecycle, currently v.8(LTS) as latest and v.7 and v.6(LTS).
Usage
It's pretty simple and straightforward.
Bulk Extensions are made on DbContext and are used with entities List (supported both regular and Async methods):
context.BulkInsert(entities); context.BulkInsertAsync(entities);
context.BulkInsertOrUpdate(entities); context.BulkInsertOrUpdateAsync(entities); //Upsert
context.BulkInsertOrUpdateOrDelete(entities); context.BulkInsertOrUpdateOrDeleteAsync(entiti);//Sync
context.BulkUpdate(entities); context.BulkUpdateAsync(entities);
context.BulkDelete(entities); context.BulkDeleteAsync(entities);
context.BulkRead(entities); context.BulkReadAsync(entities);
context.BulkSaveChanges(); context.BulkSaveChangesAsync();
-MySQL when running its Test for the first time execute sql command (local-data): SET GLOBAL local_infile = true;
-SQLite requires package: SQLitePCLRaw.bundle_e_sqlite3 with call to SQLitePCL.Batteries.Init()
Batch Extensions are made on IQueryable DbSet and can be used as in the following code segment.
They are done as pure sql and no check is done whether some are prior loaded in memory and are being Tracked.
(updateColumns is optional param in which PropertyNames added explicitly when need update to it's default value)
Info about lock-escalation in SQL Server with Batch iteration example as a solution at the bottom of code segment.
// Delete
context.Items.Where(a => a.ItemId > 500).BatchDelete();
context.Items.Where(a => a.ItemId > 500).BatchDeleteAsync();
// Update (using Expression arg.) supports Increment/Decrement
context.Items.Where(a => a.ItemId <= 500).BatchUpdate(a => new Item { Quantity = a.Quantity + 100});
context.Items.Where(a => a.ItemId <= 500).BatchUpdateAsync(a => new Item {Quantity=a.Quantity+100});
// can be as value '+100' or as variable '+incrementStep' (int incrementStep = 100;)
// Update (via simple object)
context.Items.Where(a => a.ItemId <= 500).BatchUpdate(new Item { Description = "Updated" });
context.Items.Where(a => a.ItemId <= 500).BatchUpdateAsync(new Item { Description = "Updated" });
// Update (via simple object) - requires additional Argument for setting to Property default value
var updateCols = new List<string> { nameof(Item.Quantity) }; //Update 'Quantity' to default val:'0'
var q = context.Items.Where(a => a.ItemId <= 500);
int affected = q.BatchUpdate(new Item { Description="Updated" }, updateCols); //result assigned aff.
// Batch iteration (useful in same cases to avoid lock escalation)
do {
rowsAffected = query.Take(chunkSize).BatchDelete();
} while (rowsAffected >= chunkSize);
// Truncate
context.Truncate<Entity>();
context.TruncateAsync<Entity>();
Performances
Following are performances (in seconds)
- For SQL Server (v. 2019):
Ops\Rows | EF 100K | Bulk 100K | EF 1 MIL. | Bulk 1 MIL. |
---|---|---|---|---|
Insert | 11 s | 3 s | 60 s | 15 s |
Update | 8 s | 4 s | 84 s | 27 s |
Delete | 50 s | 3 s | 5340 s | 15 s |
TestTable has 6 columns (Guid, string x2, int, decimal?, DateTime), all inserted and 2 were updated.
Test done locally on configuration: INTEL i7-10510U CPU 2.30GHz, DDR3 16 GB, SSD SAMSUNG 512 GB.
For small data sets there is an overhead since most Bulk ops need to create Temp table and also Drop it after finish.
Probably good advice would be to use Bulk ops for sets greater than 1000 (condition in DbContext or Repository).
Bulk info
If Windows Authentication is used then in ConnectionString there should be Trusted_Connection=True; because Sql credentials are required to stay in connection.
Another Conn.Str. config that can be useful for operations with extremely large data sets is ConnectionTimeout that can be increased from default 15 s to 60 or more to avoid 'Execution Timeout' if it were to occur.
When used directly each of these operations are separate transactions and are automatically committed.
And if we need multiple operations in single procedure then explicit transaction should be used, for example:
using (var transaction = context.Database.BeginTransaction())
{
context.BulkInsert(entities1List);
context.BulkInsert(entities2List);
transaction.Commit();
}
// or with newer synax as of C# 8.0 (auto disposable objects)
using var transaction = context.Database.BeginTransaction();
context.BulkInsert(entities1List);
context.BulkInsert(entities2List);
transaction.Commit();
BulkInsertOrUpdate method can be used when there is need for both operations but in one connection to database.
It makes Update when PK(PrimaryKey) is matched, otherwise does Insert.
BulkInsertOrUpdateOrDelete effectively synchronizes table rows with input data.
Those in Db that are not found in the list will be deleted.
Partial Sync can be done on table subset using expression set on config with method:
bulkConfig.SetSynchronizeFilter<Item>(a => a.Quantity > 0);
Not supported for SQLite (Lite has only UPSERT statement) nor currently for PostgreSQL. Way to achieve there sync functionality is to Select or BulkRead existing data from DB, split list into sublists and call separately Bulk methods for BulkInsertOrUpdate and Delete.
BulkRead (SELECT and JOIN done in Sql)
Used when need to Select from big List based on Unique Prop./Columns specified in config UpdateByProperties
// instead of WhereIN which will TimeOut for List with over around 40 K records
var entities = context.Items.Where(a=> itemsNames.Contains(a.Name)).AsNoTracking().ToList();//SQL IN
// or JOIN in Memory that loads entire table
var entities = context.Items.Join(itemsNames, a => a.Name, p => p,(a,p)=>a).AsNoTracking().ToList();
// USE
var items = itemsNames.Select(a => new Item { Name = a }).ToList(); // Items list with only Name set
var bulkConfig = new BulkConfig { UpdateByProperties = new List<string> { nameof(Item.Name) } };
context.BulkRead(items, bulkConfig); //Items list will be loaded from Db with data(other properties)
Useful config ReplaceReadEntities that works as Contains/IN and returns all which match the criteria (not unique).
Example of special use case when need to BulkRead child entities after BulkReading parent list.
SaveChanges uses Change Tracker to find all modified(CUD) entities and call proper BulkOperations for each table.
Because it needs tracking it is slower than pure BulkOps but still much faster than regular SaveChanges.
With config OnSaveChangesSetFK setting FKs can be controlled depending on whether PKs are generated in Db or in memory.
Support for this method was added in version 6 of the library.
Before calling this method newly created should be added into Range:
context.Items.AddRange(newEntities); // if newEntities is parent list it can have child sublists
context.BulkSaveChanges();
Practical general usage could be made in a way to override regular SaveChanges and if any list of Modified entities entries is greater then say 1000 to redirect to Bulk version.
Note: Bulk ops have optional argument Type type that can be set to type of Entity if list has dynamic runtime objects or is inherited from Entity class.
BulkConfig arguments
Bulk methods can have optional argument BulkConfig with properties (bool, int, string, object, List<string>):
PROPERTY : DEFAULTvalue
----------------------------------------------------------------------------------------------
1 PreserveInsertOrder: true, 21 PropertiesToInclude: null,
2 SetOutputIdentity: false, 22 PropertiesToIncludeOnCompare: null,
3 SetOutputNonIdentityColumns: true, 23 PropertiesToIncludeOnUpdate: null,
4 LoadOnlyIncludedColumns: false, 24 PropertiesToExclude: null,
5 BatchSize: 2000, 25 PropertiesToExcludeOnCompare: null,
6 NotifyAfter: null, 26 PropertiesToExcludeOnUpdate: null,
7 BulkCopyTimeout: null, 27 UpdateByProperties: null,
8 TrackingEntities: false, 28 ReplaceReadEntities: false,
9 UseTempDB: false, 29 EnableShadowProperties: false,
10 UniqueTableNameTempDb: true, 30 CustomSqlPostProcess: null,
11 CustomDestinationTableName: null, 31 IncludeGraph: false,
12 CustomSourceTableName: null, 32 OmitClauseExistsExcept: false,
13 CustomSourceDestinationMappingColumns: null, 33 DoNotUpdateIfTimeStampChanged: false,
14 OnConflictUpdateWhereSql: null, 34 SRID: 4326,
15 WithHoldlock: true, 35 DateTime2PrecisionForceRound: false,
16 CalculateStats: false, 36 TemporalColumns: { "PeriodStart", "PeriodEnd" },
17 SqlBulkCopyOptions: Default, 37 OnSaveChangesSetFK: true,
18 SqlBulkCopyColumnOrderHints: null, 38 IgnoreGlobalQueryFilters: false,
19 DataReader: null, 39 EnableStreaming: false,
20 UseOptionLoopJoin:false, 40 ApplySubqueryLimit: 0
----------------------------------------------------------------------------------------------
METHOD: SetSynchronizeFilter<T>
SetSynchronizeSoftDelete<T>
If we want to change defaults, BulkConfig should be added explicitly with one or more bool properties set to true, and/or int props like BatchSize to different number. Config also has DelegateFunc for setting Underlying-Connection/Transaction, e.g. in UnderlyingTest.
When doing update we can chose to exclude one or more properties by adding their names into PropertiesToExclude, or if we need to update less then half column then PropertiesToInclude can be used. Setting both Lists are not allowed.
When using the BulkInsert_/OrUpdate methods, you may also specify the PropertiesToIncludeOnCompare and PropertiesToExcludeOnCompare properties (only for SqlServer). By adding a column name to the PropertiesToExcludeOnCompare, will allow it to be inserted and updated but will not update the row if any of the other columns in that row did not change. For example, if you are importing bulk data and want to remove from comparison an internal CreateDate or UpdateDate, you add those columns to the PropertiesToExcludeOnCompare.
Another option that may be used in the same scenario are the PropertiesToIncludeOnUpdate and PropertiesToExcludeOnUpdate properties. These properties will allow you to specify insert-only columns such as CreateDate and CreatedBy.
If we want Insert only new and skip existing ones in Db (Insert_if_not_Exist) then use BulkInsertOrUpdate with config
PropertiesToIncludeOnUpdate = new List<string> { "" }
Additionally, there is UpdateByProperties for specifying custom properties, by which we want update to be done.
When setting multiple props in UpdateByProps then match done by columns combined, like unique constrains based on those cols.
Using UpdateByProperties while also having Identity column requires that Id property be Excluded.
Also, with PostgreSQL when matching is done it requires UniqueIndex so for custom UpdateByProperties that do not have Un.Ind., it is temporarily created in which case method can not be in transaction (throws: current transaction is aborted; CREATE INDEX CONCURRENTLY cannot run inside a transaction block).
Similar is done with MySQL by temporarily adding UNIQUE CONSTRAINT.
If NotifyAfter is not set it will have same value as BatchSize while BulkCopyTimeout when not set, has SqlBulkCopy default, which is 30 seconds and if set to 0 it indicates no limit.
SetOutputIdentity have a purpose only when PK has Identity (usually int type with AutoIncrement), while if PK is Guid(sequential) created in Application there is no need for them.
Also, Tables with Composite Keys have no Identity column, so no functionality for them in that case either.
var bulkConfig = new BulkConfig { SetOutputIdentity = true, BatchSize = 4000 };
context.BulkInsert(entities, bulkConfig);
context.BulkInsertOrUpdate(entities, new BulkConfig { SetOutputIdentity = true }); //e.g.
context.BulkInsertOrUpdate(entities, b => b.SetOutputIdentity = true); //BulkConfig with Action arg.
PreserveInsertOrder is true by default and makes sure that entities are inserted to Db as ordered in entitiesList.
When a table has Identity column (int autoincrement) with 0 values in list, they will temporarily be automatically changed from 0s into range -N:-1.
Or it can be manually set with proper values for order (Negative values used to skip conflict with existing ones in Db).
Here single Id value itself doesn't matter, db will change it to next in sequence, what matters is their mutual relationship for sorting.
Insertion order is implemented with TOP in conjunction with ORDER BY. so/merge-into-insertion-order.
This config should remain true when SetOutputIdentity is set to true on Entity containing NotMapped Property. issues/76
When using SetOutputIdentity Id values will be updated to new ones from database.
With BulkInsertOrUpdate on SQLServer for those that will be updated it has to match with Id column, or other unique column(s) if using UpdateByProperties in which case orderBy done with those props instead of ID, due to how Sql MERGE works. To preserve insert order by Id in this case alternative would be first to use BulkRead and find which records already exist, then split the list into 2 lists entitiesForUpdate and entitiesForInsert without configuring UpdateByProps).
Also for SQLite combination of BulkInsertOrUpdate and IdentityId automatic set will not work properly since it does not have full MERGE capabilities like SqlServer. Instead list can be split into 2 lists, and call separately BulkInsert and BulkUpdate.
SetOutputIdentity is useful when BulkInsert is done to multiple related tables that have Identity column.
After Insert is done to the first table, we need Id-s (if using Option 1) that were generated in Db because they are FK(ForeignKey) in second table.
It is implemented with OUTPUT as part of MERGE Query, so in this case, even the Insert is not done directly to TargetTable but to TempTable and then Merged with TargetTable.
When used Id-s will be updated on entitiesList, and if PreserveInsertOrder is set to false then entitiesList will be cleared and reloaded.
If Entity has Json column with null value and we set OutputIdentity then also set OutputNonIdentity to false, because JsonNull mapping throws an exception.
SetOutputNonIdentityColumns used only when SetOutputIdentity is set to true, and if this remains True (which is default) all columns are reloaded from Db.
When changed to false, only the Identity column is loaded to reduce load back from DB for efficiency.
Example of SetOutputIdentity with parent-child FK related tables:
int numberOfEntites = 1000;
var entities = new List<Item>();
var subEntities = new List<ItemHistory>();
for (int i = 1; i <= numberOfEntites; i++)
{
var entity = new Item { Name = $"Name {i}" };
entity.ItemHistories = new List<ItemHistory>()
{
new ItemHistory { Remark = $"Info {i}.1" },
new ItemHistory { Remark = $"Info {i}.2" }
};
entities.Add(entity);
}
// Option 1 (recommended)
using (var transaction = context.Database.BeginTransaction())
{
context.BulkInsert(entities, new BulkConfig { SetOutputIdentity = true });
foreach (var entity in entities) {
foreach (var subEntity in entity.ItemHistories) {
subEntity.ItemId = entity.ItemId; // sets FK to match linked PK that was generated in DB
}
subEntities.AddRange(entity.ItemHistories);
}
context.BulkInsert(subEntities);
transaction.Commit();
}
// Option 2 using Graph (only for SQL Server and only for simple relationship parent-child)
// - all entities in relationship with main ones in list are BulkInsertUpdated
context.BulkInsert(entities, b => b.IncludeGraph = true);
// Option 3 with BulkSaveChanges() - uses ChangeTracker so little slower then direct Bulk
context.Items.AddRange(entities);
context.BulkSaveChanges();
When CalculateStats set to True the result returned in BulkConfig.StatsInfo
(StatsNumber-Inserted/Updated/Deleted).
If used for pure Insert (with Batching) then SetOutputIdentity should also be configured because Merge is required.
TrackingEntities can be set to True if we want to have tracking of entities from BulkRead or if SetOutputIdentity is set.
WithHoldlock means Serializable isolation level that locks the table (can have negative effect on concurrency).
_ Setting it False can optionally be used to solve deadlock issue Insert.
UseTempDB when set then BulkOperation has to be inside Transaction.
UniqueTableNameTempDb when changed to false, temp table name will be only 'Temp' without random numbers.
CustomDestinationTableName can be set with 'TableName' only or with 'Schema.TableName'.
CustomSourceTableName when set enables source data from specified table already in Db, so input list not used and can be empty.
CustomSourceDestinationMappingColumns dict can be set only if CustomSourceTableName is configured and it is used for specifying Source-Destination column names when they are not the same. Example in test DestinationAndSourceTableNameTest
.
EnableShadowProperties to add (normal) Shadow Property and to persist value. Disables automatic discriminator, use manual method.
CustomSqlPostProcess If used, should be set to valid pure Sql syntax, that would be run after main operation but before deleting temporary tables. One practical use case would be to move data from TempOutput table (set UniqueTableNameTempDb to False know the name) into a some Log table, optionally using FOR JSON PATH (example test: CustomSqlPostProcessTest).
IncludeGraph when set, all entities that have relations with main ones from the list are also merged into theirs tables.
OmitClauseExistsExcept removes the clause from Merge statement, required when having noncomparable types like XML, and useful when need to activate triggers even for same data.
_ Also in some sql collation, small and capital letters are considered same (case-insensitive) so for BulkUpdate set it false.
DoNotUpdateIfTimeStampChanged if set checks TimeStamp for Concurrency, ones with conflict will not be updated.
Return info will be in BulkConfig.TimeStampInfo object within field NumberOfSkippedForUpdate
and list EntitiesOutput
.
SRID Spatial Reference Identifier - for SQL Server with NetTopologySuite.
DateTime2PrecisionForceRound If dbtype datetime2 has precision less then default 7, example 'datetime2(3)' SqlBulkCopy does Floor instead of Round so when this Property is set then Rounding will be done in memory to make sure inserted values are same as with regular SaveChanges.
TemporalColumns are shadow columns used for Temporal table. Default elements 'PeriodStart' and 'PeriodEnd' can be changed if those columns have custom names.
OnSaveChangesSetFK is used only for BulkSaveChanges. When multiply entries have FK relationship which is Db generated, this set proper value after reading parent PK from Db. IF PK are generated in memory like are some Guid then this can be set to false for better efficiency.
ReplaceReadEntities when set to True result of BulkRead operation will be provided using replace instead of update. Entities list parameter of BulkRead method will be repopulated with obtained data. Enables functionality of Contains/IN which will return all entities matching the criteria (does not have to be by unique columns).
UseOptionLoopJoin when set it appends 'OPTION (LOOP JOIN)' for SqlServer, to reduce potential deadlocks on tables that have FKs. Use this sql hint as a last resort for experienced devs and db admins.
ApplySubqueryLimit Default is zero '0'. When set to larger value it appends: LIMIT 'N', to generated query. Used only with PostgreSql.
DataReader can be used when DataReader is also configured and when set it is propagated to SqlBulkCopy util object.
EnableStreaming can be set to True if want to have tracking of entities from BulkRead or when SetOutputIdentity is set, useful for big field like blob, binary column.
SqlBulkCopyOptions is Enum (only for SqlServer) with [Flags] attribute which enables specifying one or more options:
Default, KeepIdentity, CheckConstraints, TableLock, KeepNulls, FireTriggers, UseInternalTransaction
If need to set Identity PK in memory, Not let DB do the autoincrement, then need to use KeepIdentity:
var bulkConfig = new BulkConfig { SqlBulkCopyOptions = SqlBulkCopyOptions.KeepIdentity };
Useful for example when copying from one Db to another.
OnConflictUpdateWhereSql<T> To define conditional updates on merges, receives (existingTable, insertedTable).
--Example: bc.OnConflictUpdateWhereSql = (ex, in) => $"{in}.TimeUpdated > {ex}.TimeUpdated";
SetSynchronizeFilter<T> A method that receives and sets expression filter on entities to delete when using BulkInsertOrUpdateOrDelete. Those that are filtered out will be ignored and not deleted.
SetSynchronizeSoftDelete<T> A method that receives and sets expresion on entities to update property instead of deleting when using BulkInsertOrUpdateOrDelete.
bulkConfig.SetSynchronizeSoftDelete<SomeObject>(a => new SomeObject { IsDeleted = true });
Last optional argument is Action progress (Example in EfOperationTest.cs RunInsert() with WriteProgress()).
context.BulkInsert(entitiesList, null, (a) => WriteProgress(a));
For parallelism, important notes are:
-SqlBulk in Parallel
-Concurrent operations not run in the same Context instance
-Import data to a single unindexed table with table level lock
Library supports Global Query Filters and Value Conversions as well.
Additionally BatchUpdate and named Property works with EnumToString Conversion
It can map OwnedTypes, also next are links with info how to achieve
NestedOwnedTypes and
OwnedInSeparateTable
On PG when Enum is in OwnedType it needs to have Converter explicitly configured in OnModelCreating
Table splitting is somewhat specific but could be configured in the way Set TableSplit
With Computed and Timestamp Columns, it will work in a way that they are automatically excluded from Insert. And when combined with SetOutputIdentity they will be Selected.
Spatial types, like Geometry, are also supported and if an Entity has one, clause EXIST ... EXCEPT is skipped because it's not comparable.
Performance for bulk ops measured with ActivitySources
named: 'BulkExecute' (tags: 'operationType', 'entitiesCount')
Bulk Extension methods can be Overridden if required, for example to set AuditInfo.
If having problems with Deadlock, there is useful info in issue/46.
TPH (Table-Per-Hierarchy) inheritance model can be set in 2 ways.
First is automatically by Convention, in which case the Discriminator column is not directly in the Entity but is Shadow Property.
And second is to explicitly define Discriminator property in Entity and configure it with .HasDiscriminator()
.
An important remark regarding the first case is that since we can not directly set a Discriminator to certain value we need first to add list of entities to DbSet where it will be set and after that we can call Bulk operation. Note that SaveChanges are not called, and we could optionally turn off TrackingChanges for performance. Example:
public class Student : Person { ... }
context.Students.AddRange(entities); //adding to Context so Shadow property 'Discriminator' gets set
context.BulkInsert(entities);
TPT (Table-Per-Type) way it is supported.
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- EFCore.BulkExtensions.MySql (>= 8.1.2)
- EFCore.BulkExtensions.PostgreSql (>= 8.1.2)
- EFCore.BulkExtensions.Sqlite (>= 8.1.2)
- EFCore.BulkExtensions.SqlServer (>= 8.1.2)
NuGet packages (143)
Showing the top 5 NuGet packages that depend on EFCore.BulkExtensions:
Package | Downloads |
---|---|
Elsa.Persistence.EntityFramework.Core
Elsa is a set of workflow libraries and tools that enable lean and mean workflowing capabilities in any .NET Core application. This package provides Entity Framework Core entities used by the various Elsa persistence EF Core providers. |
|
CyberEye.Common.Lib
Package chứa các hàm tiện ích và common |
|
GreatUtilities.Core
Essencial tools to agile development. |
|
Ssg.Core
Ssg.Core Is Core of Framework fro web application |
|
Adriva.Extensions.Analytics
Adriva Analytics Server Extensions |
GitHub repositories (11)
Showing the top 5 popular GitHub repositories that depend on EFCore.BulkExtensions:
Repository | Stars |
---|---|
cq-panda/Vue.NetCore
(已支持sqlsugar).NetCore、.Net6、Vue2、Vue3、Vite、TypeScript、Element plus+uniapp前后端分离,全自动生成代码;支持移动端(ios/android/h5/微信小程序。http://www.volcore.xyz/
|
|
Webreaper/Damselfly
Damselfly is a server-based Photograph Management app. The goal of Damselfly is to index an extremely large collection of images, and allow easy search and retrieval of those images, using metadata such as the IPTC keyword tags, as well as the folder and file names. Damselfly includes support for object/face detection.
|
|
dotnetcore/sharding-core
high performance lightweight solution for efcore sharding table and sharding database support read-write-separation .一款ef-core下高性能、轻量级针对分表分库读写分离的解决方案,具有零依赖、零学习成本、零业务代码入侵
|
|
WolvenKit/WolvenKit
Community Mod editor/creator for REDengine games.
|
|
VahidN/EFCoreSecondLevelCacheInterceptor
EF Core Second Level Cache Interceptor
|
Version | Downloads | Last updated |
---|---|---|
8.1.2 | 2,075 | 11/20/2024 |
8.1.1 | 366,562 | 9/6/2024 |
8.1.0 | 291,091 | 7/30/2024 |
8.0.4 | 833,089 | 5/23/2024 |
8.0.3 | 273,062 | 4/29/2024 |
8.0.2 | 722,651 | 2/19/2024 |
8.0.1 | 577,629 | 12/14/2023 |
8.0.0 | 278,706 | 11/21/2023 |
8.0.0-rc.1.2 | 27,698 | 10/4/2023 |
8.0.0-rc.1 | 1,410 | 9/13/2023 |
8.0.0-preview.7 | 624 | 8/31/2023 |
7.8.1 | 210,348 | 12/14/2023 |
7.1.6 | 913,966 | 8/29/2023 |
7.1.5 | 219,934 | 7/25/2023 |
7.1.4 | 155,451 | 7/10/2023 |
7.1.3 | 82,500 | 7/3/2023 |
7.1.2 | 327,209 | 5/26/2023 |
7.1.1 | 113,013 | 5/13/2023 |
7.1.0 | 165,784 | 4/26/2023 |
7.0.4 | 124,190 | 4/19/2023 |
7.0.3 | 197,751 | 4/13/2023 |
7.0.2 | 4,569 | 4/13/2023 |
7.0.1 | 693,537 | 1/28/2023 |
7.0.0 | 97,539 | 1/22/2023 |
6.8.1 | 340,921 | 12/18/2023 |
6.7.16 | 216,268 | 8/29/2023 |
6.7.15 | 433,778 | 7/25/2023 |
6.7.14 | 38,749 | 7/10/2023 |
6.7.13 | 8,069 | 7/4/2023 |
6.7.12 | 133,686 | 5/26/2023 |
6.7.11 | 37,851 | 5/13/2023 |
6.7.1 | 80,832 | 4/26/2023 |
6.7.0 | 433,666 | 1/22/2023 |
6.6.5 | 491,890 | 1/5/2023 |
6.6.4 | 116,359 | 12/19/2022 |
6.6.3 | 3,877 | 12/19/2022 |
6.6.2 | 268,341 | 12/7/2022 |
6.6.1 | 3,030 | 12/7/2022 |
6.6.0 | 4,122 | 12/7/2022 |
6.6.0-rc.2 | 155 | 12/7/2022 |
6.6.0-rc.1 | 157 | 12/7/2022 |
6.5.6 | 3,791,301 | 8/8/2022 |
6.5.5 | 404,798 | 7/21/2022 |
6.5.4 | 245,627 | 7/12/2022 |
6.5.3 | 69,503 | 7/7/2022 |
6.5.2 | 278,401 | 6/20/2022 |
6.5.1 | 166,843 | 6/14/2022 |
6.5.0 | 608,368 | 5/10/2022 |
6.4.4 | 952,071 | 4/15/2022 |
6.4.3 | 7,084 | 4/14/2022 |
6.4.2 | 815,145 | 3/17/2022 |
6.4.1 | 716,580 | 2/21/2022 |
6.4.0 | 278,076 | 2/8/2022 |
6.3.9 | 162,779 | 2/7/2022 |
6.3.8 | 7,563 | 2/6/2022 |
6.3.7 | 20,631 | 2/3/2022 |
6.3.6 | 3,770 | 2/3/2022 |
6.3.5 | 3,251 | 2/3/2022 |
6.3.4 | 16,577 | 2/2/2022 |
6.3.3 | 86,062 | 1/31/2022 |
6.3.2 | 34,269 | 1/28/2022 |
6.3.1 | 103,329 | 1/20/2022 |
6.3.0 | 101,837 | 1/15/2022 |
6.2.9 | 789,940 | 1/14/2022 |
6.2.8 | 70,421 | 1/9/2022 |
6.2.7 | 8,904 | 1/9/2022 |
6.2.6 | 974,685 | 1/1/2022 |
6.2.5 | 3,217 | 12/30/2021 |
6.2.4 | 20,998 | 12/25/2021 |
6.2.3 | 151,469 | 12/17/2021 |
6.2.2 | 19,195 | 12/15/2021 |
6.2.1 | 32,560 | 12/13/2021 |
6.2.0 | 23,428 | 12/10/2021 |
6.1.9 | 19,383 | 12/9/2021 |
6.1.8 | 10,645 | 12/9/2021 |
6.1.7 | 2,944 | 12/9/2021 |
6.1.6 | 8,520 | 12/8/2021 |
6.1.5 | 8,009 | 12/8/2021 |
6.1.4 | 244,715 | 12/4/2021 |
6.1.3 | 8,952 | 12/3/2021 |
6.1.2 | 10,891 | 12/2/2021 |
6.1.1 | 64,753 | 11/29/2021 |
6.1.0 | 125,562 | 11/28/2021 |
6.0.9 | 47,522 | 11/26/2021 |
6.0.8 | 27,958 | 11/26/2021 |
6.0.7 | 51,633 | 11/26/2021 |
6.0.6 | 76,026 | 11/24/2021 |
6.0.5 | 22,571 | 11/24/2021 |
6.0.4 | 61,599 | 11/21/2021 |
6.0.3 | 63,391 | 11/18/2021 |
6.0.2 | 54,518 | 11/12/2021 |
6.0.1 | 141,621 | 11/10/2021 |
6.0.0 | 308,656 | 11/10/2021 |
6.0.0-rc.2 | 3,278 | 10/15/2021 |
6.0.0-rc.1 | 714 | 10/6/2021 |
5.4.2 | 535,273 | 1/14/2022 |
5.4.1 | 205,554 | 11/12/2021 |
5.4.0 | 870,615 | 9/9/2021 |
5.3.9 | 45,448 | 9/5/2021 |
5.3.8 | 15,382 | 9/2/2021 |
5.3.7 | 238,742 | 8/10/2021 |
5.3.6 | 8,049 | 8/10/2021 |
5.3.5 | 15,190 | 8/9/2021 |
5.3.4 | 4,099 | 8/9/2021 |
5.3.3 | 6,352 | 8/9/2021 |
5.3.2 | 11,248 | 8/6/2021 |
5.3.1 | 87,875 | 7/26/2021 |
5.3.0 | 68,656 | 7/19/2021 |
5.2.9 | 17,742 | 7/19/2021 |
5.2.8 | 100,854 | 7/9/2021 |
5.2.7 | 25,926 | 7/8/2021 |
5.2.6 | 38,838 | 7/5/2021 |
5.2.5 | 92,086 | 6/20/2021 |
5.2.4 | 14,098 | 6/17/2021 |
5.2.3 | 53,602 | 6/10/2021 |
5.2.2 | 271,021 | 5/19/2021 |
5.2.1 | 24,282 | 5/17/2021 |
5.2.0 | 28,477 | 5/13/2021 |
5.1.9 | 6,242 | 5/13/2021 |
5.1.8 | 63,363 | 5/9/2021 |
5.1.7 | 25,773 | 5/5/2021 |
5.1.6 | 8,374 | 5/4/2021 |
5.1.5 | 5,557 | 5/3/2021 |
5.1.4 | 4,918 | 5/2/2021 |
5.1.3 | 3,718 | 5/1/2021 |
5.1.2 | 51,003 | 4/24/2021 |
5.1.1 | 3,996 | 4/23/2021 |
5.1.0 | 43,532 | 4/20/2021 |
5.0.9 | 46,622 | 4/19/2021 |
5.0.8 | 15,002 | 4/19/2021 |
5.0.7 | 45,973 | 4/12/2021 |
5.0.6 | 18,752 | 4/8/2021 |
5.0.5 | 30,222 | 4/7/2021 |
5.0.4 | 85,302 | 4/7/2021 |
5.0.3 | 10,510 | 4/7/2021 |
5.0.2 | 12,896 | 4/4/2021 |
5.0.1 | 10,975 | 4/3/2021 |
5.0.0 | 25,071 | 4/2/2021 |
3.6.6 | 328,837 | 2/26/2022 |
3.6.5 | 122,301 | 1/14/2022 |
3.6.4 | 6,943 | 1/7/2022 |
3.6.3 | 412,296 | 8/5/2021 |
3.6.2 | 22,788 | 7/26/2021 |
3.6.1 | 342,325 | 4/7/2021 |
3.6.0 | 12,408 | 4/7/2021 |
3.5.8 | 119,652 | 3/30/2021 |
3.5.7 | 3,452 | 3/30/2021 |
3.5.6 | 31,774 | 3/29/2021 |
3.5.5 | 12,879 | 3/27/2021 |
3.5.4 | 4,486 | 3/26/2021 |
3.5.3 | 2,890 | 3/26/2021 |
3.5.2 | 33,219 | 3/25/2021 |
3.5.1 | 10,355 | 3/24/2021 |
3.5.0 | 7,440 | 3/24/2021 |
3.4.9 | 15,695 | 3/23/2021 |
3.4.8 | 71,687 | 3/22/2021 |
3.4.7 | 12,243 | 3/21/2021 |
3.4.6 | 6,047 | 3/20/2021 |
3.4.5 | 2,900 | 3/20/2021 |
3.4.4 | 3,375 | 3/19/2021 |
3.4.3 | 13,805 | 3/18/2021 |
3.4.2 | 10,205 | 3/17/2021 |
3.4.1 | 11,068 | 3/17/2021 |
3.4.0 | 42,094 | 3/15/2021 |
3.3.9 | 167,612 | 3/15/2021 |
3.3.8 | 9,652 | 3/14/2021 |
3.3.7 | 6,794 | 3/13/2021 |
3.3.6 | 14,072 | 3/13/2021 |
3.3.5 | 161,555 | 3/10/2021 |
3.3.4 | 35,209 | 3/9/2021 |
3.3.3 | 104,636 | 3/8/2021 |
3.3.2 | 7,713 | 3/7/2021 |
3.3.1 | 439,205 | 2/7/2021 |
3.3.0 | 19,377 | 2/7/2021 |
3.2.7 | 527,821 | 12/13/2020 |
3.2.6 | 6,292 | 12/12/2020 |
3.2.5 | 1,170,837 | 10/15/2020 |
3.2.4 | 205,567 | 10/6/2020 |
3.2.3 | 199,635 | 9/23/2020 |
3.2.2 | 21,503 | 9/21/2020 |
3.2.1 | 8,595 | 9/21/2020 |
3.2.0 | 29,834 | 9/17/2020 |
3.1.6 | 339,510 | 9/11/2020 |
3.1.5 | 1,032,805 | 7/14/2020 |
3.1.4 | 203,974 | 7/7/2020 |
3.1.3 | 33,035 | 7/3/2020 |
3.1.2 | 13,584 | 7/1/2020 |
3.1.1 | 1,144,557 | 3/25/2020 |
3.1.0 | 1,305,203 | 12/18/2019 |
3.0.5 | 95,511 | 12/10/2019 |
3.0.4 | 68,718 | 12/1/2019 |
3.0.3 | 31,770 | 11/17/2019 |
3.0.2 | 10,370 | 11/12/2019 |
3.0.1 | 6,783 | 11/11/2019 |
3.0.0 | 175,769 | 10/4/2019 |
3.0.0-rc | 5,532 | 9/25/2019 |
2.6.4 | 913,179 | 11/30/2019 |
2.6.3 | 418,283 | 9/21/2019 |
2.6.2 | 3,636 | 9/21/2019 |
2.6.1 | 120,454 | 9/12/2019 |
2.6.0 | 258,004 | 8/19/2019 |
2.6.0-rc | 5,216 | 7/24/2019 |
2.5.2 | 197,288 | 7/22/2019 |
2.5.1 | 25,195 | 7/14/2019 |
2.5.0 | 119,317 | 7/14/2019 |
2.4.9 | 128,497 | 7/4/2019 |
2.4.8 | 3,420 | 7/4/2019 |
2.4.7 | 229,041 | 5/28/2019 |
2.4.6 | 126,494 | 4/22/2019 |
2.4.5 | 66,235 | 4/8/2019 |
2.4.4 | 96,451 | 3/18/2019 |
2.4.3 | 36,143 | 3/5/2019 |
2.4.2 | 9,257 | 3/3/2019 |
2.4.1 | 350,694 | 3/3/2019 |
2.4.0 | 225,225 | 2/4/2019 |
2.3.9 | 88,114 | 1/31/2019 |
2.3.8 | 19,776 | 1/29/2019 |
2.3.7 | 101,611 | 1/4/2019 |
2.3.6 | 19,300 | 12/27/2018 |
2.3.5 | 71,461 | 12/10/2018 |
2.3.4 | 21,780 | 11/27/2018 |
2.3.3 | 3,775 | 11/27/2018 |
2.3.2 | 13,237 | 11/26/2018 |
2.3.1 | 14,253 | 11/25/2018 |
2.3.0 | 13,827 | 11/23/2018 |
2.2.9 | 13,594 | 11/23/2018 |
2.2.8 | 3,986 | 11/22/2018 |
2.2.7 | 4,200 | 11/22/2018 |
2.2.6 | 72,385 | 11/21/2018 |
2.2.5 | 8,408 | 11/16/2018 |
2.2.4 | 37,836 | 11/14/2018 |
2.2.3 | 16,356 | 11/11/2018 |
2.2.2 | 66,975 | 11/8/2018 |
2.2.1 | 8,029 | 11/8/2018 |
2.2.0 | 140,053 | 11/8/2018 |
2.1.9 | 59,070 | 10/28/2018 |
2.1.8 | 37,291 | 10/10/2018 |
2.1.7 | 139,866 | 7/26/2018 |
2.1.6 | 13,956 | 7/13/2018 |
2.1.5 | 6,654 | 7/12/2018 |
2.1.4 | 14,515 | 7/7/2018 |
2.1.3 | 11,779 | 6/24/2018 |
2.1.2 | 11,709 | 6/21/2018 |
2.1.1 | 38,162 | 6/14/2018 |
2.1.0 | 23,555 | 6/11/2018 |
2.0.9 | 10,442 | 6/11/2018 |
2.0.8 | 132,913 | 5/15/2018 |
2.0.7 | 34,418 | 3/28/2018 |
2.0.6 | 7,849 | 3/24/2018 |
2.0.5 | 18,377 | 2/12/2018 |
2.0.4 | 4,429 | 2/6/2018 |
2.0.3 | 5,147 | 1/30/2018 |
2.0.2 | 14,828 | 11/13/2017 |
2.0.1 | 13,232 | 9/7/2017 |
2.0.0 | 19,477 | 9/4/2017 |
2.0.0-rc | 3,656 | 9/4/2017 |
1.1.0 | 6,057 | 9/4/2017 |
1.0.8 | 4,216 | 8/31/2017 |
1.0.7 | 5,079 | 8/15/2017 |
1.0.6 | 4,391 | 8/9/2017 |
1.0.5 | 5,176 | 7/11/2017 |
1.0.4 | 4,684 | 6/23/2017 |
1.0.3 | 4,600 | 5/30/2017 |
1.0.2 | 4,931 | 5/15/2017 |
1.0.1 | 4,292 | 5/12/2017 |
1.0.0 | 17,041 | 5/12/2017 |
several updates