EF Core - In Memory Database - HasDefaultValue is being ignored

Viewed 345

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?

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>();
Related