-
Notifications
You must be signed in to change notification settings - Fork 56
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
BulkInsert ignoring session context value set before insert #581
Comments
Hello @bptillman , Thank you for reporting. My developer tried to reproduce the issue, but everything was working with him. One major difference I can see in his code is that we were opening the connection, but since you are in a transaction, I would assume you do the same. I'm coming back from vacation next Monday, so I will look with him next week. Best Regards, Jon |
@JonathanMagnan thank you for checking on this. I have done some more digging and I have found that this has actually has nothing to do with the session context value in my triggers and instead has to do with two other items causing the issue I'm seeing, depending on how they are set, and what version of this extension package that I am using, so I apologize for sending you down the rabbit hole of looking at that initially. In my code, the EffectiveFromDate has a default SQL value set in our model builder like so:
Having this in the code, plus having the Bulk Insert option for IncludeGraph being false appears to cause the issue of the date set in code not being persisted to the database on version 7.22.2. I tested this out with the combinations of
Only under scenario 1 did I find that the value I set in my code for EffectiveFromDate not making it into the database. Running Sql Profiler I was able to see why in that scenario, since the merge statement being run did not end up including EffectiveFromDate when IncludeGraph was false and the SetDefaultValueSql was declared, as you can see from this query I grabbed:
Upon updating to 7.102.2.4 the behavior is different under the same 4 scenarios I mentioned above with IncludeGraph and the SetDefaultValueSql. On this newer version I see the following:
So you can see how now that as long as SetDefaultValueSql is declared, no matter if we use IncludeGraph = true or false, it does not persist the date we set it to. We are re-evaluating the need to use SetDefaultValueSql in our code, but for now it is there and we end up needing to bulk insert different objects that have the EffectivefromDate columns with IncludeGraph = false and for others true. |
Hello @bptillman , Indeed, there is a major breaking change in the As documented, you can still have the same behavior under the latest version by using the You can also change how the default value is handled with the option ForceValueGeneratedStrategy We are currently improving this part when a value is provided to align more like the Let me know if that explains the current behavior correctly and if my answer provides the solution you currently need. Best Regards, Jon |
Hello @bptillman , Since our last conversation, we haven't heard from you. Let me know if you need further assistance. Best regards, Jon |
@JonathanMagnan thank you for that advice. I finally had some time to test it out, and the right combination of setting IncludeGraph and ForceValueGeneratedStrategy set to OnAddOrUpdate allowed my code to work as it did in previous versions. Thanks! |
Awesome, We made a lot of progress in handling default values better. I will let you know when the new version will be ready. Best Regards, Jon |
Description
In our code base we have a table that has a trigger on it that checks for a value set in the session context and skips the trigger logic, otherwise it proceeds with executing the trigger logic like so:
When we perform a Bulk Insert to this table in code, we first make a call to set that session context value so that the trigger should return and not proceed with its remaining logic, but when executing the code below, we are seeing that the triggers logic after the return statement ends up being executed since afterwards when looking in the database, we see the EffectiveFromDate being set to the UTC Now Date, instead of the date we set it to before the BulkInsert.
This all leads me to believe that a different session context is used for the BulkInsert, despite specifying to use the same existing context with the ContextFactory.
I have also tried using the PreBulkInsert event to try and set the session context value there, but it did not appear to make a difference:
Further technical details
The text was updated successfully, but these errors were encountered: