-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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 for inserting/updating tables with triggers (not use OUTPUT when batching off) #1441
Comments
We should look at allowing batching to be switched off and then not use OUTPUT |
@rowanmiller, any news on this? - or do you have a hint on what I can do to mitigate the problem? It must be a very common problem, that records are inserted/updated on tables that have insert/update triggers associated. |
Hey - we aren't planning to tackle this right now. I think if you disable batching for the moment it should work...
|
Hi @rowanmiller, thanks for getting back. Unfortunately it doesn't work. The OUTPUT statement is generated even for batch sizes of 1. Do you have any other suggestion? |
@rmja - nothing off the top of my head. I'm clearing this issue up for us to re-triage since when we put it on the backlog we thought disabling batching would be a feasible workaround. |
Any update on this issue, with the lack of sp support at this time, triggers can be very helpful... |
Please excuse me for opening a new issue, when one exists already. I only found this issue after filing the above one. Is there any update regarding this issue? Without this issue resolved we would be unable to use EF 7 in our application, which we are currently porting from Asp.Net 4 with EF 6 to Asp.Net 5 with EF 7. Where not being able to use EF 7 would partially invalidate the reasons behind our complete re-write / port. |
Bumping from Backlog to 7.0.0 for us to look at before RTM |
Hi @rowanmiller I can understand that the team is extremely busy, but could you possibly let us know more or less when this feature may be looked at? At this point this is seriously preventing our implementation as the systems we work with have triggers present which affect us with this specific issue. Any estimate would be greatly appreciated. |
We are going to look at it after RC1 (next month) but before RTM. |
@rowanmiller We are hoping to complete the setup of our internal preview environment for our customers in about 2 weeks. Could we possibly get involved with making this feature happen? If we can perhaps we can just hear the rough ideas that you had in mind, and the best starting points in the repo's. Without this feature we are totally unable to proceed, as the databases we work with have audit triggers on them that are out of our control. Currently on local dev, we simply remove the offenders, but this was only doable up till now. |
In case it helps, this is what I had in mind:
|
@rowanmiller, @louislewis2 we are experimenting with a minimal solution in /src/EntityFramework.SqlServer/Update/SqlServerUpdateSqlGenerator.cs, assuming .MaxBatchSize(1): AppendInsertCommandHeader(commandStringBuilder, name, schema, writeOperations);
- if (readOperations.Length > 0)
- {
- AppendOutputClause(commandStringBuilder, readOperations);
- }
AppendValuesHeader(commandStringBuilder, writeOperations);
AppendValues(commandStringBuilder, writeOperations);
for (var j = 1; j < valueSetCount; j++)
{
commandStringBuilder.Append(",").AppendLine();
AppendValues(commandStringBuilder, modificationCommands[j].ColumnModifications.Where(o => o.IsWrite).ToArray());
}
commandStringBuilder.Append(BatchCommandSeparator).AppendLine();
+ if (readOperations.Length > 0)
+ {
+ var keyOperations = operations.Where(o => o.IsKey).ToArray();
+ AppendSelectAffectedCommand(commandStringBuilder, name, schema, readOperations, keyOperations);
+ } Perhaps this will be of some use to those more intimately familiar with the codebase, in devising a more comprehensive solution. |
@divega @rowanmiller Hi guys, do you have any comments regarding the above 'fix'? |
Clearing the milestone so that we can re-discuss this in triage |
@AndriySvyryd for RTM we should do the simplest thing needed to support triggers. Swapping to a batch size of 1 would be an ok requirement to make it work. |
…ith triggers Add commandPosition argument to methods on IUpdateSqlGenerator to provide a unique id for a modification command in a batch Fixes #1441
…ith triggers Add commandPosition argument to methods on IUpdateSqlGenerator to provide a unique id for a modification command in a batch Fixes #1441
So I just ran into this problem too. I see a fix was checked in. What do you recommend I do to get it? Is there an imminent release, or do I need to pull and build this myself? |
The next release is more than a month away. You could try out the nightly build from https://www.myget.org/F/aspnetvnext |
@rmja |
Let there be a table
Table1
in SQL Server with an AFTER INSERT trigger. The produced SQL is:The problem is that SQL reports the following error for such a statement if a trigger exists on the table:
The target table 'Table1' of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause.
I have been trying a possible fix where the following code is changed for
AppendBulkInsertOperation()
in SqlServerSqlGenerator.cs:The following query is then produced, and it seems to work as expected. I am not sure about the
GetTypeMapping()
on the typeMapper.The text was updated successfully, but these errors were encountered: