DeleteWithOutput for Azure SQL (SqlServer.2017) generates unsupported query
See original GitHub issueHi guys, I found a little problem (which I can bypass).
I have quite trivial code:
using var scope = _serviceProvider.CreateScope();
var dbContext = scope.ServiceProvider.GetRequiredService<MyDbContext>().CreateLinqToDbConnection();
var deleted = await dbContext.GetTable<CachedResult>()
.Where(r => r.Expired < DateTime.UtcNow)
.DeleteWithOutputAsync(stoppingToken);
It seems that it generates SQL query, which is not supported in Azure SQL:
-- SqlServer.2017 (asynchronously)
DECLARE @UtcNow DateTime2
SET @UtcNow = '2022-02-28T15:42:39.9584090'
DELETE [r]
OUTPUT
*
FROM
[mytable].[CachedResults] [r]
WHERE
[r].[Expired] < @UtcNow
16:55:19.818 759860 ERR # 7 LinqToDB.Data.DataConnection:() :: Error
Exception: Microsoft.Data.SqlClient.SqlException
Message : Incorrect syntax near '*'.
at Microsoft.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__188_0(Task`1 result)
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
at LinqToDB.Data.DataConnection.ExecuteReaderAsync(CommandBehavior commandBehavior, CancellationToken cancellationToken)
I think a star (*) needs to be prefixed with deleted.
to have a query like:
DELETE [r]
OUTPUT
deleted.*
FROM
[mytable].[CachedResults] [r]
WHERE
[r].[Expired] < @UtcNow
I will be much appreciated to any comments.
Environment details
linq2db version: 3.6.0 Database Server: Azure SQL (SqlServer.2017) Database Provider: linq2db.EntityFrameworkCore v6.6.1 Operating system: WIN10 .NET: v6.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
DELETE (Transact-SQL) - SQL Server
Returns deleted rows, or expressions based on them, as part of the DELETE operation. The OUTPUT clause is not supported in any DML...
Read more >Delete statement with OUTPUT clause in azure sql
The problem was due to column order being switched for two columns. Thanks for confirming that the OUTPUT clause was working as expected...
Read more >The OUTPUT Clause for INSERT and DELETE Statements
In this article, I will provide a set of examples to show case the use of OUTPUT clause for INSERT and DELETE statements....
Read more >Python serverless functions to query Azure SQL DB
This article will show how to get data from Azure SQL in the Serverless Python app.
Read more >Delete records from single Azure DB table that has no linking
Change your query from delete from [databasename].[dbo].[tblImages] where companyid = 123. to delete from [dbo].
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks, we are planning to release reworked
OUTPUT
support in next release. Will make sure it works with new versionClosing for now. Will reopen if you still have an issue with it.