Firstly this is just a simple feature that is supported by at least EF Core for SQL Server, but for Oracle (the provider implemented by Oracle), I'm not so sure if it's supported.
Simply I have an entity class like this:
public class Item {
public int Id {get;set;}
public DateTime CreatedDateUtc {get;set;}
}
The problem is how to configure the EF core to auto-generate database's date to CreatedDateUtc
each time inserting without having to set that value on client side?
Here's what I've tried:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Item>()
.Property(e => e.CreatedDateUtc)
.ValueGeneratedOnAdd();
}
But after running add-migration
, the generated class is just empty like this:
protected override void Up(MigrationBuilder migrationBuilder)
{
}
protected override void Down(MigrationBuilder migrationBuilder)
{
}
So actually it does nothing with that configuration (not supported?).
Also the first thing is to generate a datetime value, the second important thing is to generate a UTC datetime value. I believe in the feasibility for the first requirement whereas the second seems to be unfeasible at least with Oracle EF Core? (nuget name: Oracle.EntityFrameworkCore
).
I am keen to achieve the first requirement, even if the second requirement is impossible. At least we need some work-around then.