I have an entity named Affaire as below:
[Key]
public string IdAffaire { get; set; }
public string Title { get; set; }
public string Note { get; set; }
I also have an entity named Suite as below:
[Key]
public string IdSuite { get; set; }
public string IdAffaire { get; set; }
public string Description { get; set; }
[ForeignKey("IdAffaire")]
public virtual Affaire Affaire { get; set; }
One affaire can have multiple suites.
Each suite is related to one affaire.
In my suite table, I have the following records:
IdSuite/IdAffaire/Description
0001/12.345/Description1
0001/13.666/DescriptionA
0002/13.666/DescriptionB
0003/13.666/DescriptionC
0004/13.666/DescriptionD
The problem: in my code, if I try to get a list of all suites, I get the following:
IEnumerable<Suite> suites
0001/12.345/Description1
0001/12.345/DescriptionA
0002/13.666/DescriptionB
0003/13.666/DescriptionC
0004/13.666/DescriptionD
As you can see, something’s wrong with the data returned??
Do you have an idea?
Thank you very much 🙂
Edited for posting code:
...
IEnumerable<Suite> suites;
...
When I debug this line of code and inspect the suites variable, I received wrong result (as showed up).
Maybe the problem is that I need to define correctly my primary key on table Suite: composed of two fields IdAffaire an IdSuite How can I do?
Ok, I found the problem: because I have a composite primary key, I need to define it like this:
Suite entity:
Thank you anyway 🙂