Comments (13)
You almost got it. You don't have to specify the DbSet.
List<DictWord> dw = new List<DictWord>();
DictWord w = new DictWord { WordID = WordID_counter, Word = "word1", WordStat = 20 };
dw.Add(w);
context.BulkInsert(dw);
Best Regards,
Jonathan
from entityframework-extensions.
Thank you, but why don't I have to specify the DbSet? It kinda relies on <DictWord> type or something(he-he))?
Anyway I tried it with MSSQL LocalDB and it worked! (And it worked much faster. Strange, I measured the time it takes to context.SaveChanges() and context.BulkSaveChanges() the first one took 0 seconds, the second one 0,027 seconds, funny))
I actually need to use other DBMS, when I switch to PostgreSQL it says "The Provider could not be resolved. You must explicity set the Provider.". Is there any chance to fix it?
from entityframework-extensions.
DbSet
We don’t have to specify the DbSet since by using the entity type we can easily find out which DbSet the entity belongs. However, we added this idea to our suggestions list to allow also to make bulk operations directly from DbSet.
Benchmarking
Most people make the same error when performing benchmarking and forget about the JIT compilation. The Entity Framework has been already JIT compiled from a previous statement, so you are currently comparing the time of SaveChanges vs BulkSaveChanges + JIT Compilation, which is unfair. You must always call both methods once before performing your benchmark.
Provider
The PostgreSQL is currently under development and almost completed. The provider will be supported tomorrow or next week, so it is very close.
from entityframework-extensions.
COOL!!! You're good))
from entityframework-extensions.
Is it still not supported in new 3.9.26 version?
from entityframework-extensions.
It partially supported in the version 3.9.26, we almost completed all the test required. Only a few tests with some column type are remaining. The provider took a little bit more time than expected because I was sick in the past few days.
We really hope to release the version this Friday.
from entityframework-extensions.
Hi,
When I use the follow code to insert about 3 million record to one table, it throw a OutOfMemoryException.
The array is Array object.
this.db.BulkInsert<TB_Statistics>(array, (batchOption)=> batchOption.BatchSize = 1000);
So I use the followed code, but why the upper code throw a exception?
int insertCount = 0, batchSize = 1000;
while (insertCount < array.Length)
{
this.db.BulkInsert<TB_Statistics>(array.Skip(insertCount).Take(batchSize));
insertCount += batchSize;
}
from entityframework-extensions.
Hello Hesi,
This error happens because BulkInsert transfers all values into a DataTable for performing the insertion. After some millions of entities, the DataTable become too large and throw this error.
The code will be modified this week-end and a new version should be available within the few first day of the next week fixing this issue. We will remove the DataTable code to allow streaming via a DataReader instead.
from entityframework-extensions.
And I found another bug.
I need update 139000 records , so I use the follows code to update.
var updateIndex = 0;
List updateTaskList = new List();
while (updateIndex < changedComplex.Count)
{
int[] updateSubArray = changedComplex.SubArray(ref updateIndex, batchSize);
var task = this.db.TB_Statistics
.Where((a) => updateSubArray.Contains(a.Id) && a.LastStatisticsTradeDate.HasValue)
.UpdateFromQueryAsync((a) => new TB_Statistics { LastStatisticsTradeDate = null });
updateTaskList.Add(task);
}
Task.WaitAll(updateTaskList.ToArray());
Then,
System.AggregateException
HResult=-2146233088
Message=发生一个或多个错误。(some errors happened bala bala....)
Source=mscorlib
StackTrace:
在 System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)
在 System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeout)
在 System.Threading.Tasks.Task.WaitAll(Task[] tasks)
在 Web.Controllers.ConditionController.<>c__DisplayClass5_4.b__8() 在 E:\TotalDevelop\StockAnalyze\Web\Controllers\ConditionController.cs 中: 第 271 行
在 System.Threading.Tasks.Task.InnerInvoke()
在 System.Threading.Tasks.Task.Execute()
InnerException:
HResult=-2147024809
Message=已添加了具有相同键的项。(Have add the same key bala bala...)
Source=mscorlib
StackTrace:
在 System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
在 System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) 在 . . ( , IEnumerable
1 )
在 . . (IEnumerable1 ) 在 . . ( ) 在 . . ( ) 在 . . ( ) 在 . . ( ) 在 . . ( ) 在 . . ( ) 在 . . ( ) 在 . . ( ) 在 . . ( ) 在 . . ( ) 在 . . ( ) 在 . . (Type , ) 在 . . (String , ParameterExpression[] , Object[] , Type ) 在 . . (Type , Type , String , Object[] ) 在 . . (IQueryable , String , Object[] ) 在 DbContextExtensions.UpdateFromQuery[TEntity](IQueryable
1 query, Expression1 updateExpression, Action
1 bulkOperationFactory)
在 DbContextExtensions.UpdateFromQuery[TEntity](IQueryable1 query, Expression
1 updateExpression)
from entityframework-extensions.
Thank you Hesi,
We will check this one after fixing the streaming issue.
from entityframework-extensions.
We just released the v3.9.29 which support all common type for PostgreSQL,
Can you give it a try and let us know if you get some error?
We did over 3500 unit tests for this provider, but we are aware we still have to support some uncommon database type.
from entityframework-extensions.
We just released the v3.9.30 which supports DataTable Batch Size. We did not success to support streaming because to much code was involved and we don't want to change to much our library (we never know about side effect!). We will for sure code in the next major version using streaming instead of DataTable.
The fix is very similar to what you did
using (var ctx = new CodeFirstEntities())
{
// Examples
ctx.BulkInsert(list, operation =>
{
operation.DataTableBatchSize = 1000000;
operation.BatchSize = 1000;
});
}
Every 1,000,000 records, a new data table will be created and a bulk insert will be performed. The BulkInsert will insert record in the destination table in batch of 1000.
We will check the issue about UpdateFromQuery tomorrow.
from entityframework-extensions.
We just released the v3.9.32 fixing the UpdateFromQueryAsync issues.
Make sure to use a different context instance for every task else our code will fail. Unfortunately, the library doesn't support yet shared DbContext instance in a concurrent scenario.
We will close this issue since every request should be completed. Feel free to re-open it or create a new one.
from entityframework-extensions.
Related Issues (20)
- BulkInsert Exception using NpgSql and jsonb in .NET 8 HOT 11
- Trial for EF core 7 HOT 3
- BulkInsert taking 20+ min for 80 000 data rows HOT 3
- Force output does not work for merge. HOT 3
- Invalid Cast. The update expression must be of type MemberInitExpression. HOT 3
- Bulk Operations for Postgres does not respect the PermanentTable setting HOT 2
- Avoid Prepared Statements for Bulk operations HOT 6
- WhereBulkContains throwing System.ArgumentNullException: 'Value cannot be null. (Parameter 'name')' HOT 15
- BulkUpdate and BulkMerge Do Not Apply Any Changes To The Table with Owned Entity HOT 1
- BulkSaveChanges results in Foreign Key Constraint Violation but SaveChanges works HOT 3
- BulkMerge is Causing Violation of PRIMARY KEY constraint HOT 1
- BulkInsert: System.IndexOutOfRangeException: 'There is no row at position 0.' HOT 4
- While inserting new record through BulkMerge it's not overriding default constraint value HOT 3
- The type initializer for 'Z.BulkOperations.LicenseManager' threw an exception HOT 13
- `PublicExtensions` static dictionaries are filling up HOT 4
- SQLite Invalid cast from 'System.String' to 'System.Guid' HOT 4
- IDbCommandInterceptor does not fire when using BulkInsert or BulkDelete HOT 2
- WhereBulkContains does not work when table inherit from another table HOT 1
- Feat: Conditional insert HOT 3
- EFcore 8 UpdateFromQuery generates invalid sql HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from entityframework-extensions.