I am using EF code first to create my migrations for an azure sql DB. I would like to start using "update" and "append only" ledger tables. I know i can set the whole DB to be update ledger, so that when I create new tables in the usual way, they will be automatically update ledger tables with a history table. But I would like to instead have the option of choosing which tables are update and which as append only. I can't find any recourses on how I would go about this. One of the tables I want to be append only would in fact be my MigrationsHistory table. Is there a way to do this with EF core?
--- Update [clarification] ---
I might now have been clear enough. Above.
What i am looking for is on how i would archive the required result using entity framework code first.
In other words using sql i could do something like this:
CREATE SCHEMA [AccessControl];
GO
CREATE TABLE [AccessControl].[KeyCardEvents]
(
[ID] INT NOT NULL,
[Timestamp] Datetime2 NOT NULL
)
WITH (LEDGER = ON (APPEND_ONLY = ON));
To get a table that would be append only. But if i want to create the model first like this:
public class AccessControl
{
public Int Id { get; set; }
public DateTime Timestamp{ get; set; }
}
Is there perhaps an attribute i could add to the class so that EF knows to make it an append only table? Or is there another way that can be done?
Also, please note that i also am curious how to make the __EFMigationsHistory table be an append only table. This table gets created the first time a migration is run on a database.
There seems to be no support for Azure Sql Database Ledger tables in EF Core Code First at the moment.
Even looking at the current in-development code for EF 7 (the next EF Core version at the time of writing) SqlServerMigrationsSqlGenerator.cs class, the Generate method overload with the following signature
protected override void Generate(
CreateTableOperation operation,
IModel? model,
MigrationCommandListBuilder builder,
bool terminate = true)
is only able to fill in the "table options" (that will be provided in the WITH clause as a part of the generated CREATE TABLE statement) with:
SYSTEM_VERSIONING = ON option aloneMEMORY_OPTIMIZED = ON optionThe first corresponds to, eg:
modelBuilder
.Entity<Employee>()
.ToTable("Employees", b => b.IsTemporal());
While the second one corresponds to, eg:
modelBuilder.Entity<Blog>().IsMemoryOptimized();
Unfortunately there is currently no mention of Ledger tables support neither in EF Core 7.0 Plan, nor in EF Core Issues in GitHub..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With