c# - How do I select entries through an intermediary table relationship? -


this has obvious answer, drawing blank somehow. have 3 tables, let's called:

people    addresses   addressdetails 

i using entity framework (so above models relationships set up). trying select data typical ef linq query (doesn't matter whether method or query syntax).

people , addresses many-to-many. addresses , addressdetails one-to-one(/zero). need select entries addressdetails correspond particular personid. know connection there since can select addresses personid = n, , each address has 1 addressdetails entry, how do properly?


i tried following:

            var details =                  p in db.people                 p.id = n                 in p.addresses                 ad in a.details                 select ad;  

visual studio highlights "details" in a.details , gives following:

'api.models.addresses' not contain definition 'api.models.details"...

i ef telling me doesn't see relationship. did verify one-to-one there. ideas? ef doesn't see because there no fk in addresses table? (the addresses pk details pk/fk).

you should able this:

var details =      p in people     p.id = n     in p.addresses     ad in a.details     select ad;  

fyi: reference linq 101 linq samples


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -