Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EFCore Bulkextension's BulkInsertAsync not setting the id (identity field) #1299

Open
AnandSonake opened this issue Oct 23, 2023 · 2 comments

Comments

@AnandSonake
Copy link

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. Is it really fixed or am I missing anything here ? We are getting negative id in result variable the below code:

public async Task InsertAsync(List 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, not sure why BulkInsertAsync not returning the ids.

@AnandSonake
Copy link
Author

AnandSonake commented Nov 2, 2023

Is it possible to update the MERGE operation to make use of OUTPUT clause to return the IDs of records inserted using BulkInsertAsync or BulkInsert ?

Reference:
https://stackoverflow.com/questions/77343372/efcore-bulkextensions-bulkinsertasync-not-setting-the-id-identity-field?noredirect=1#comment136354159_77343372

@AKlaus
Copy link

AKlaus commented Feb 13, 2025

Can confirm the issue on the latest version v8.1.2 against the SQL Server.

Steps to reproduce are as per the OP's code:

BulkConfig bulkCOnfig = new BulkConfig 
{       
   SetOutputIdentity = true.  // This's the culprit
};
await this.BulkInsertAsync(users, bulkCOnfig);
var result = users.FirstOrDefault().Id;  // It's NULL

If the SetOutputIdentity parameter is false, then the Id gets set, but there's no way to fetch the number of affected records.

Here's the OP's post on StackOverflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants