Search code examples
asp.net-coreasp.net-identityentity-framework-core

Can EntityFramework core use deterministic Guids?


Is it possible to inject a Guid provider to aspnet / EF core so that two test runs produces the identical database content?

I'd like to diff the dump of two databases but randomised ids are a problem. I currently remove the ids but it makes the diff less than idea.


Solution

  • You can override this behavior with Fluent API

    modelBuilder.Entity<MyEntity>()
                .Property(x => x.Id)
                .HasDefaultValue(MyGuidProvider());
    

    As for actually creating MyGuidProvider() I unfortunately can't be of much help, you can try checking out this question