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

An error occurred with OUTPUT clause when a trigger is on the table #170

Closed
mikilion opened this issue Dec 2, 2016 · 9 comments
Closed

Comments

@mikilion
Copy link

mikilion commented Dec 2, 2016

Chain commands as Insert, Update or Delete with return value generate a error when a trigger is on the table:

The target table 'TableName' of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause

@Grauenwolf
Copy link
Collaborator

Can you show me the line of code you used to trigger this error?

I think I know how to fix it, but I want to make sure I address your specific use case.

@Grauenwolf
Copy link
Collaborator

And just to verify, are you using SQL Server?

@mikilion
Copy link
Author

mikilion commented Dec 5, 2016

The error occur by Chain commands as these:

dataSource.Upsert("TableName", entity).WithRefresh()...
dataSource.Insert("TableName", entity).ToInt32()...
dataSource.Insert("TableName", entity).ToObject()...

I'm using SQL Server 2016.

@Grauenwolf
Copy link
Collaborator

Dev notes.

  1. Detect tables with triggers: select * from sys.triggers
  2. If they exist, switch to using a temp table in the SQL generation as per http://stackoverflow.com/questions/13198476/cannot-use-update-with-output-clause-when-a-trigger-is-on-the-table

@mikilion
Copy link
Author

mikilion commented Dec 5, 2016

Why not provide an option to specify when to use a temporary table?

@Grauenwolf
Copy link
Collaborator

I can provide a behavior override as an advanced feature, but it really should "just work" regardless if you have triggers or not. Otherwise adding a trigger to a pre-existing table becomes a breaking change.

@Grauenwolf
Copy link
Collaborator

Inserts are now fixed. But they require a change to the Core library, so it won't be published until version 1.1.

Still need to port the fix update, delete, and maybe upsert.

@Grauenwolf
Copy link
Collaborator

Update/Delete are done. Confirmed that Upsert has the same bug.

@Grauenwolf
Copy link
Collaborator

This feature will be part of this week's Chain 1.1. release.

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

No branches or pull requests

2 participants