-1

I have a project with my school, I have to make a website like stackoverflow (possibility to add a question, a member can answer or put a comment if he have enough reputation, etc).

I have an issue with the class Vote. It should have 2 primary keys (the user and the post), but I don't know how to do that with EF Core.

Thank you for your help !

enter image description here

live2
  • 3,771
  • 2
  • 37
  • 46
Nin3s
  • 11
  • 2
  • To be precise - it's still just **ONE** primary key (since a table in a relational database can **NEVER** have more than one PK!) - but it's made up from **two columns** ..... – marc_s Dec 11 '19 at 15:49
  • Duplicate (but now the *question* is your answer): https://stackoverflow.com/q/54441615/861716 – Gert Arnold Dec 11 '19 at 16:00

1 Answers1

1

I will suggest to use fluent API:

.HasKey(vote => new { vote.upvoteId, vote.downvoteId});

Please take a look at the .HasKey() method https://www.learnentityframeworkcore.com/configuration/fluent-api/haskey-method

Hope this helps!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
RPDF
  • 76
  • 8