huysentruitw / entity-framework-core-mock

Easy Mock wrapper for mocking EFCore5 DbContext and DbSet using Moq or NSubstitute

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do I call OnModelCreating

integral-llc opened this issue · comments

All of me Entities do not use attributes to mark the keys, everything is happening inside OnModelCreating override method.
i.e.

modelBuilder.Entity<MarketplaceEntity>(entity =>
            {
                entity.ToTable("Marketplace", "Application");
                entity.HasKey(e => e.MarketplaceKey);
            });

How to call this method so the keys are properly initialized? As of now, I'm getting an exception saying the entity does not contain any property marked with KeyAttribute.

thx!

Unfortunately entity configurations like that are currently not supported. As of now, I can't tell how complex it would be to add support for it. However, currently, you can work-around this by passing your own key-factory to the call to CreateDbSetMock:

dbContextMock.CreateDbSetMock(x => x.MarketPlaces, (e, _) => e.MarketplaceKey, initialEntities);