Open Swellenator opened 4 years ago
Notes for team: In this case the property is configured for automatic concurrency with an expectation that this will work like it does in SQL Server. This is tracked by #2195. Within this, the insert of null happens because the SQLite provider doesn't support computed properties--tracked by #19682.
Should we check for one or both of these patterns in the model validator?
Model:
EntityType: Customer
Properties:
Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd
TxTimestamp (byte[]) Required Concurrency BeforeSave:Ignore AfterSave:Ignore ValueGenerated.OnAddOrUpdate
Keys:
Id PK
/cc @bricelam
My work around is:
var sql = context.Database.GenerateCreateScript();
// HACK: ef core wont put data into a rowversion column, but it is not null, so create a fake default
sql = sql.Replace("\"TxTimestamp\" BLOB NOT NULL", "\"TxTimestamp\" BLOB NOT NULL DEFAULT (randomblob(8))");
await context.Database.ExecuteSqlRawAsync(sql);
to create a default value for the column. Certainly not ideal
@bricelam I couldn't find an issue about comments/warnings in the generated code.
This exact scenario was previously discussed in https://github.com/dotnet/efcore/issues/7295
Putting this on the backlog to consider generating some form of inline warning.
Use [ConcurrencyCheck] to Manual management ConcurrencyCheck Key。 Sqlite not support [Timestamp] automaticlly(Timestamp Include RowVersion & ConcurrencyCheck)
FYI, I created https://github.com/dorssel/dotnet-ef-sqlite-timestamp
Using in memory EF Core SQLite for integration tests. When creating an entity with the following column definition:
Setting with
TxTimestamp = new byte[8] { 0, 1, 2, 3, 4, 5, 6, 7 }
I get the following error:
Microsoft.Data.Sqlite.SqliteException : SQLite Error 19: 'NOT NULL constraint failed: [TableName].TxTimestamp'.
Any ideas? It is like SQLite isn't inserting the value. Perhaps because with real SQL Server it wouldn't be able to? This model is generated from a SQL Server database and we are using database first, so I can't just change the model builder definition. (unless there is an easy way to override the one generated form the scaffold).
Additional context
Microsoft.Data.Sqlite version: 3.1.3 Target framework: netcoreapp3.1 Operating system: Win 10