One of my tables in SQL Server, has an InsteadOfInsert trigger defined, which I cannot modify. EF 6, will generate a correct
INSERT [SomeTable] ([SomeColumns]) VALUES (SomeValues)
SELECT [SomeIdenityColumn], [ROWID]
FROM [SomeTable]
WHERE @@ROWCOUNT > 0 AND [SomeIdenityColumn] = scope_identity()
but this call fails miserably, due to scope_identity() being null when coming out of the InsteadOfInsert trigger, which I cannot modify. Is there any way in EF 6 to modify the generated SQL to utilize the OUTPUT Inserted approach instead?
UPDATE
Found these two on SO:
OptimisticConcurrencyException -- SQL 2008 R2 Instead of Insert Trigger with Entity Framework
error when inserting into table having instead of trigger from entity data framework
UPDATE 2 - AKA REALLY BAD NEWS
So I have modified the generated SQL code using SSMS in an attempt to utilize INSERT INTO OUTPUT.
INSERT INTO [SomeTable] ([SomeColumns])
OUTPUT Inserted.[SomeIdenityColumn], Inserted.[ROWID]
VALUES (SomeValues)
When executing from SSMS I get this error:
Msg 334, Level 16, State 1, Line 41 The target table 'AuMine.QUOTE_STAFF_ACTIVITY' of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause.
Classic catch 22 ..