Skip to content

Commit ad43259

Browse files
committed
Previous attempt to fix pre-sql server 2016 support for temp tables missed the DisposeAsync implementation.
1 parent 8b85fee commit ad43259

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Thinktecture.EntityFrameworkCore.SqlServer/EntityFrameworkCore/TempTables/SqlServerTempTableReference.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ public async ValueTask DisposeAsync()
8888
if (!_dropTableOnDispose || _database.GetDbConnection().State != ConnectionState.Open)
8989
return;
9090

91-
await _database.ExecuteSqlRawAsync($"DROP TABLE IF EXISTS {_sqlGenerationHelper.DelimitIdentifier(Name)}").ConfigureAwait(false);
91+
await _database.ExecuteSqlRawAsync($@"
92+
IF(OBJECT_ID('tempdb..{Name}') IS NOT NULL)
93+
DROP TABLE {_sqlGenerationHelper.DelimitIdentifier(Name)};
94+
").ConfigureAwait(false);
9295
await _database.CloseConnectionAsync().ConfigureAwait(false);
9396
}
9497
catch (ObjectDisposedException ex)

0 commit comments

Comments
 (0)