You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When inserting a new row in the table, the object instance is not automatically updated - OpCounter value is null after save. Also, if I later query the data, the OpCounter value is still null. Similarly for updates.
To Reproduce
Simply run the GitHub code and review the failing test. Each test has Additional output containing EFCore logs etc. The working test suggests a solution - introduce triggers during EnsureCreated and in Migrations, similarly as per suggested solution.
Suggested solution
Create, update or delete triggers as needed during EnsureCreated and in Migrations:
protectedvoidInitializeTriggers(TestSqliteContextcontext){vartables=context.Model.GetEntityTypes();foreach(vartableintables){varprops=table.GetProperties().Where(p =>p.ClrType==typeof(byte[])&&p.ValueGenerated==Microsoft.EntityFrameworkCore.Metadata.ValueGenerated.OnAddOrUpdate&&p.IsConcurrencyToken);vartableName=table.GetTableName();foreach(varfieldinprops){string[]SQLs=newstring[]{$@"CREATE TRIGGER IF NOT EXISTS Set{tableName}_{field.Name}OnUpdate AFTER UPDATE ON [{tableName}] FOR EACH ROW BEGIN UPDATE [{tableName}] SET [{field.Name}] = randomblob(8) WHERE rowid = NEW.rowid; END ",$@"CREATE TRIGGER IF NOT EXISTS Set{tableName}_{field.Name}OnInsert AFTER INSERT ON [{tableName}] FOR EACH ROW BEGIN UPDATE [{tableName}] SET [{field.Name}] = randomblob(8) WHERE rowid = NEW.rowid; END "};foreach(varsqlinSQLs){using(varcommand=context.Database.GetDbConnection().CreateCommand()){command.CommandText=sql;command.ExecuteNonQuery();}}}}}
I have a table with the following column:
When inserting a new row in the table, the object instance is not automatically updated - OpCounter value is null after save. Also, if I later query the data, the OpCounter value is still null. Similarly for updates.
To Reproduce
Simply run the GitHub code and review the failing test. Each test has Additional output containing EFCore logs etc. The working test suggests a solution - introduce triggers during EnsureCreated and in Migrations, similarly as per suggested solution.
Suggested solution
Create, update or delete triggers as needed during EnsureCreated and in Migrations:
Change-token-Timestamp-has-no-effect-for-SQLite
Additional context
Microsoft.Data.Sqlite version:
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.7" />
Target framework:
<TargetFramework>netcoreapp3.1</TargetFramework>
Operating system:
Windows 10
The text was updated successfully, but these errors were encountered: