简体   繁体   中英

Selecting records from a third table that is related to one of the two joined tables

I have a Linq query that is joining two tables and I am trying to pull only records that has a Client that has a related Contact from a third table with an ID of 19. The ClientProjects and Clients tables have no navigation properties between them (ClientProjects is a table that comes from an outside source and can not be modified). Clients and Contacts have a many to many relationship. What is wrong with my query and what is the right way to do this?

 ClientProjects.Join(Clients.Where(a => a.Contacts.FirstOrDefault().Id == 19), a => a.ClientId, c => c.HistoricClientId, (a, c) => new {?.ContactName a.DisplayName }) 

美好的一天,尝试在Join语句中添加.Include()

    ClientProjects.Join(Clients.Include(x => x.Contacts).Where(a => a.Contacts.FirstOrDefault().Id == 19), a => a.ClientId, c => c.HistoricClientId, (a, c) => new {c.Contacts.ContactName a.DisplayName })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM