.net - What is the correct way to join 3 tables using EF -


it might because little in morning , brain not functioning correctly have question regarding entity framework , sql

lets have 2 tables

consumer consumerid name membershipnumberid

membershipentry membershipentryid entrydate membershipnumberid

a member can have membershipnumberid before having consumerid. think along lines of person collects membership number , uses number 1st time before associates consumerid.

i how want join tables can create query returns of membership entries if don't yet have consumer assoicated them.

i have tried add fk membershipentry table fails expect due missing id's in membership table.

do create 3rd table called membershipentries , have 2 fk fields?

i can create basic join using like

from item in ctx.membershipentry      join c in ctx.consumer on item.membershipnumberid  equals c.membershipnumberid      select new membershipviewmodel()      {      .....................      } 

how can ceate left outter join using ef4 include entries if dont have membership number yet assoicated them?

you not need third table join these 2 tables of data (that's why it's relational database!! woohoo!). whole point make "easy" relate , extract data. need simple sql statement!

such this:

select *  membershipentry  left outer join consumer on consumer.membershipnumberid = membershipentry.membershipnumberid 

left outer join says "give me membershipentry table if there nothing match in consumer table"

see http://www.w3schools.com/sql/sql_join_left.asp more details , examples!

note: databases may use left join sql uses left outer join


Comments