Search code examples
entity-framework-coresql-server-2017

How to make Entity Framework 7 not use OUTPUT in updates?


I get this error when I update through EF 7: "The target table 'Table' of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause."

EF 7 executes this:

exec sp_executesql N'SET IMPLICIT_TRANSACTIONS OFF;
SET NOCOUNT ON;
UPDATE [ObrazacZahtjevZaIzvanrednuPozajmicu] SET [OdbijenOdobren] = @p0
OUTPUT 1
WHERE [ObrazacZahtjevZaIzvanrednuPozajmicuId] = @p1 AND [Zakljucan] = @p2;
',N'@p1 int,@p0 bit,@p2 bit',@p1=21858,@p0=1,@p2=0

Solution

  • You need to tell EF that the table has a trigger. So in the OnModelCreating in your context, you use something like this:

    modelBuilder
        .Entity<TableWithTrigger>()
        .ToTable(t => t.HasTrigger("NameOfTrigger"));
    

    For info, this was documented in Breaking changes in EF Core 7.0 (EF7)