Skip to content

Commit 9b9e01a

Browse files
authored
Merge pull request #22 from poizan42/drop-table-if-exists-pre-sqlserver2016-take-2
Previous attempt to fix pre-sql server 2016 support for temp tables missed the DisposeAsync implementation.
2 parents 8b85fee + ad43259 commit 9b9e01a

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)