-
Notifications
You must be signed in to change notification settings - Fork 12
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
Support bulk insert on tables with triggers #51
Comments
kragoth, The merge statement is used internally to support many of the options for the bulk operations. I did some testing and discovered that if I remove the output from the merge statement, it would fix the issue you are having with the trigger. If you do use the framework this way, any database generated fields in the EF entities you are saving, will not be populated again after saving. Proposed Fix: If BulkOptions.AutoMapOutput is set to false, then the OUTPUT portion of the merge statement will no longer be generated. |
@NorthernLight1 yeah if the output is not mandatory then yeah, that would be a great fix. What's the effect of removing the output? |
Kragoth, The output is used to set any database generated fields, like an Id or CreatedDate fields, but it does result in a small performance overhead. This fix is present in the latest version (v8.0.0.6) |
@NorthernLight1 legend! We'll give it a go. :) |
@NorthernLight1 unfortunately that doesn't work. It seems to be because of this line of code
This always adds Action and Id to the output columns so an output statement is always added to the sql command. |
kragoth I will release another version soon and patch it. |
kragoth, Please try again with 8.0.0.7. The issue should be resolved. |
@NorthernLight1 this is working for us now. Thank you! |
Is your feature request related to a problem? Please describe.
BulkInsert does not support inserting into tables that have triggers.
The sql generated for bulk insert is basically
This results in the error:
The target table 't' of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause.
Describe the solution you'd like
Given the following discussions in EF around the topic: dotnet/efcore#27372
and on stackoverflow: https://stackoverflow.com/questions/13198476/cannot-use-update-with-output-clause-when-a-trigger-is-on-the-table
It seems that the only solution would be to generate an alternative insert statement if the table has a trigger.
Describe alternatives you've considered
I have used ZEntityFramework.Plus to do bulk inserts successfully. So I assume that they are not using the merge statement. But, it was a while ago and so I'm not 100% sure it was on a table with a trigger. I would need to go test it out.
The text was updated successfully, but these errors were encountered: