0

I feel like I can get things done, but, I am far from a good programmer and it is annoying me.

Using Entity Framework Core, I'm creating a project and just had to build a many to many relationship that required me to use the Fluent API to set the ends correctly.

The moment I did this, I wasn't able to compile the project or really do anything as the default identity framework that was on the project was interfering. The error was:

The entity type 'IdentityUserLogin<string>' requires a primary key to be defined.

I spent a good amount of time trying to debug this issue with no luck what so ever. After a quick search, I found this question which whilst not exactly my issue (I have a single DbContext), the solution was to add the following:

base.OnModelCreating(modelBuilder);

The moment I did this, the project compiled and everything worked as expected.

So, my question really is - why? Can someone explain what is happening, why it's happening - but more importantly, it's great that Stack Overflow exists and I was able to get the answer, but, if you are a novice programmer, how would you understand and diagnose this issue?

I feel like whilst Stack Overflow is great for getting answers, I'm being lazy and I really want to learn why things are happening the way they are.

wil
  • 2,019
  • 2
  • 15
  • 14

1 Answers1

0

It appears this is the answer to your why question. Not so sure about how you would know as a novice programmer, hopefully someone can provide more insight.

All configurations for your identity entities are defined into IdentityDbContext. So if you create your custom context ApplicationDbContext which derives from IdentityDbContext you need to call this line base.OnModelCreating(modelBuilder); before adding configurations for own entities

Stackoverflow Answer

eVolve
  • 1,340
  • 1
  • 11
  • 30