Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • first of all, thanks a lot for all the help. Really appreciated it. On the post that you suggested, the scenario is the same but on the annotation solution described on the accepted answer, you can see that there's no annotation for the foreignKeys tha compose the multi-part primary key. On that example, MemberComment class does not have any annotation that links the Atribute MemberID to the Member nor CommentID to the Comment. Similarly, in my case, I am able to create a PK with IDClient and IDResearch, but then I cannot link the Client and Research attributes. Commented Apr 12, 2014 at 14:47
  • @MarceloMyara: The reason why the MemberComment example doesn't have ForeignKey attributes is only that the FK properties MemberID, etc. have "conventional" names (nav. property name + "ID"). So, EF mappings conventions detect these properties as FKs automatically. However, in your example you have "unconventional" names (your are starting with "ID"). Therefore you must apply attributes to tell EF that IDClient is the FK for the Client navigation property because it doesn't recognize it by convention. But your usage of the [ForeignKey] attribute is OK, I don't see a problem. Commented Apr 12, 2014 at 14:58
  • that's the thing. When I include something like the [real] code that I posted on the original question's edit, i receive the mentioned error (on the add-migration)... Commented Apr 12, 2014 at 15:58
  • 1
    @MarceloMyara: Do Pesquisa or Paciente have composite primary keys? The exception is strange otherwise for this model. Or are there other relationships where PacientePesquisa is involved that the exception might refer to? My Fluent mapping code does exactly the same as your annotations. I would be surprised if that works but the annotations don't. Commented Apr 12, 2014 at 17:48
  • Hey, you're the best! I owe you one... That was the case, I had another relationship that involved the [PacientePesquisa] key (and I was forgetting to alter it too). As soon as I corrected this relationship, everything worked great! Cheers. :D Commented Apr 12, 2014 at 18:29