Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF Core - In Memory Database - HasDefaultValue is being ignored

I am running into an issue where I try to add a default value for a few columns. However in my integration tests even though my model is setup in following way:

modelBuilder.Entity<User>().Property(x => x.Idx).HasDefaultValue(Guid.NewGuid());

the default value is being ignored and I always end up with an empty GUID.

Is there any way how elegantly solve the default valuel for In Memory Database?

like image 268
Jakub Holovsky Avatar asked Oct 20 '25 02:10

Jakub Holovsky


1 Answers

Using .HasValueGenerator<T>() did the trick for me.

In my case it would be:

modelBuilder.Entity<User>().Property(x => x.Idx).HasValueGenerator<GuidValueGenerator>();
like image 56
Jakub Holovsky Avatar answered Oct 21 '25 15:10

Jakub Holovsky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!