OK, so i have my Client table/entity. I also have a Medical table/entity. And because my Client can have multiple Medical records i created a resolving table/entity called ClentMedial which consists of 3 attributes, ID, ClientID and MedicalID.
I have figured out how to create a ClientMedical record when specifying the ID explicitly using the following code:
ClientMedical cm = new ClientMedical();
var med = (from m in db.Medicals where m.Id == 1 select m).First();
cm.Client = client;
cm.Medical = med;
client.ClientMedicals.Add(cm);
db.SaveChanges();
However i don't know how to iterate through the Clients ClientMedical collection to display the medical condition (the Medical entity has a condition attribute). I am new to Entity Framework. I have a Client form which shows all the info about a particular client, what i want to do is to be able to show/add/remove medical conditions for a particular client.
I am sorry if this is a bit vague i tried to explain it as best as i can.
EDIT:
Was able to access the data like this:
IQueryable<Medical> med =
from p in db.ClientMedicals
where p.Client.Id == client.Id
select p.Medical;
foreach (Medical m in med)
{
MessageBox.Show(m.Condition);
}
If someone has better way please say.