Closed rainerbiz closed 3 months ago
You need to make sure the locally generated value is marked as temporary. Easiest is probably to take the default StringValueGenerator
and override GeneratesTemporaryValues
.
Here's an example.
class MyContext : DbContext
{
public DbSet<TEST> TEST { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
optionsBuilder.UseFirebird("...");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<TEST>(b =>
{
b.Property(x => x.ID)
.ValueGeneratedOnAdd()
.HasValueGenerator<MyStringKeyGenerator>();
});
}
}
class TEST
{
public string ID { get; set; }
public double? FOO { get; set; }
}
class MyStringKeyGenerator : StringValueGenerator
{
public override bool GeneratesTemporaryValues => true;
}
Thank you very much!
I totally ignored the GeneratesTemporaryValues
and did not think much about it, when i tried around with a custom generator.
Now it works perfectly!
Hey,
I am trying to get the functionality of
DatabaseGeneratedOption.Computed
on a Key Column. The primary key of the table is a string which is getting changed in a Before Insert Trigger in the database. If my field is not a key and I useDatabaseGeneratedOption.Computed
, everything works as I want and the value will be updated with a Returning in the query. But I cannot use this option on a key field, cause of theValueGeneratedOnUpdate
, which cannot be used for a key column. So then I tried theDatabaseGeneratedOption.Identity
which only adds theValueGeneratedOnAdd
. But theDatabaseGeneratedOption.Identity
Options generates a GUID for the field, which I don’t want. Then I replaced the ValueGenerator with a new Generator that leaves the field as an empty string. But then the Returning command will not be added in the Insert Query.Is there currently no option to make the
DatabaseGeneratedOption.Computed
functionality work on aValueGeneratedOnAdd
key field? I also tried arround withUseIdentityColumn
andUseSequenceTrigger
. I just want to fill my field with an empty string and let it update after the insert using a returning command.I am sorry if this question is wrong here, but I tried everything and looked through the code, but I could not find a solution to my problem.