1

In EF Core 2, I was able to update and retrieve entities in a single query using FromSql and issuing an UPDATE-OUTPUT query.

It looked something like this:

return await _baseDbContext.MyEntity
                           .FromSql($@"UPDATE {_baseDbContext.SchemaName}.MyEntity
                            SET STATUS = ""InProgress"",
                                UpdatedAt = SYSDATETIMEOFFSET()
                            OUTPUT
                                INSERTED.Id, INSERTED.Name,
                                INSERTED.Status, INSERTED.Deleted, INSERTED.CreatedAt, INSERTED.CreatedBy, INSERTED.CreatedByUserId,
                                INSERTED.UpdatedAt, INSERTED.UpdatedBy, INSERTED.UpdatedByUserId, INSERTED.Version
                            FROM { _baseDbContext.SchemaName}.MyEntity le
                            WHERE le.Status = ""Failed""")
                .ToListAsync(cancellationToken);

Now after upgrading to EF Core 3, it is complaining that

"FromSqlRaw or FromSqlInterpolated was called with non-composable SQL and with a query composing over it. Consider calling AsEnumerable after the FromSqlRaw or FromSqlInterpolated method to perform the composition on the client side.

I am able to perform a FromSqlRaw or FromSqlInterpolated if I just put in a SELECT query.

Does EF core 3 not support UPDATE-OUTPUT queries anymore?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
roshan
  • 323
  • 8
  • 22

1 Answers1

0

Solved it by adding .IgnoreQueryFilters() based on the the answer posted here: Include with FromSqlRaw and stored procedure in EF Core 3.1

roshan
  • 323
  • 8
  • 22