Closed tschennie closed 2 years ago
Hi @tschennie,
The CreateUniqueMethodOptions
only sets up the options for the DbContext so that shouldn't cause the type of exception. I expect its how you reset / create the database. The best thing would be to provide me with:
1.
DbContextOptions<InvoiceDbContext>? options = this.CreateUniqueMethodOptions<InvoiceDbContext>(); await using InvoiceDbContext dbContext = new(options); dbContext.Database.EnsureClean();
2. Message: Microsoft.Data.SqlClient.SqlException: Failed to delete XXX.dbo.Invoices table because this is not a supported operation for temporal tables with system versioning.
SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction)
TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean isAsync, Int32 timeout, Boolean asyncWrite)
SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 completion, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String methodName) SqlCommand.ExecuteNonQuery() RelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject) MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary
2 parameterValues)
MigrationCommandExecutor.ExecuteNonQuery(IEnumerable1 migrationCommands, IRelationalConnection connection) <>c__2
1.3 operation, Func
3 verifySucceeded)
ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, TState state, Func2 operation, Func
2 verifySucceeded)
ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, TState state, Func2 operation) ExecutionStrategyExtensions.Execute[TState](IExecutionStrategy strategy, TState state, Action
1 operation)
CleanDatabaseExtensions.EnsureClean(DatabaseFacade databaseFacade, Boolean setUpSchema)
GetInvoicesHandlerTests.Handle_Admin_AllInvoices() Zeile 59
GetInvoicesHandlerTests.Handle_Admin_AllInvoices() Zeile 71
--- End of stack trace from previous location ---
And this is the configuration for the temporal table:
pBuilder.ToTable("Invoices",
tableBuilder => tableBuilder.IsTemporal(temporalTableBuilder =>
{
temporalTableBuilder.UseHistoryTable("InvoicesHistory");
}));
The dbContext.Database.EnsureClean()
method uses the SQL DROP
command, which won't work on a temporal tables. You should use:
dbContext.Database.EnsureDeleted();
dbContext.Database.EnsureCreated();
This deleted the current database and then creates a new database. This is slower but will work with temporal tables.
Hello,
we are using the CreateUniqueMethodOptions for testing. Now we added a temporal table and we are getting following error while executing the tests:
Microsoft.Data.SqlClient.SqlException: Failed to delete the XXX table because this is not a supported operation for temporal tables with system versioning.
If I delete the table on my own, the test works fine once. But then, I will get the error again...
Does this method supports temporal tables und if yes, how?
Thanks, Jenny