EFCore Bulkextension's BulkInsertAsync not setting the id (identity field).
we are using EFCore.BulkExtensions version 6.3.3 and as per this link this issue is fixed in v5.3.7. Anyone aware about whether it is really fixed or am I missing anything here ? We are getting negative id in result variable the below code:
public async Task InsertAsync(List<User> users)
{
BulkConfig bulkCOnfig = new BulkConfig()
{
SetOutputIdentity = true
};
await this.BulkInsertAsync(users, bulkCOnfig);
var result = users.FirstOrDefault().Id;
}
But if I use BulkInsertOrUpdateAsync then I'm getting Ids all records except the last one.
1条答案
按热度按时间2ic8powd1#
Try EFCore.BulkExtensions.MIT:
GitHub: https://github.com/videokojot/EFCore.BulkExtensions.MIT
NuGet: https://www.nuget.org/packages/EFCore.BulkExtensions.MIT/
It is MIT fork of EFCore.BulkExtensions, I fixed there multiple issues regrading setting the output idenity, so maybe your issue is fixed there.
This fork fixes issues not fixed in original:
Choose major version (6.x/7.x/8.x) based on EFCore version you are using (actual code and fixes are shared).
I also refactored and cleaned the project, so the anyone can simply checkout and run tests locally.
I added the tests for BulkInsertAsync and they all pass: https://github.com/videokojot/EFCore.BulkExtensions.MIT/pull/70/files
If you can give me reproduction scenario, the fix will be probably easy.
Disclaimer: I am the maintainer of this MIT fork.