In my application, a company can have many employees, and each employee can have multiple email addresses.
The database schema links the tables as follows:
Company β CompanyEmployeeXref β Employee β EmployeeAddressXref β Email
I am using Entity Framework and I want to create a LINQ query that returns the company name and comma-separated list of email addresses of employees. Here is the query I'm trying to make:
from c in Company join ex in CompanyEmployeeXref on c.Id equals ex.CompanyId join e in Employee on ex.EmployeeId equals e.Id join ax in EmployeeAddressXref on e.Id equals ax.EmployeeId join a in Address on ax.AddressId equals a.Id select new { c.Name, a.Email.Aggregate(x=>x + ",") } Desired Output: "Company1", "a @ company1.com, b @ company1.com, c @ company1.com "" Company2 "," a @ company2.com, b @ company2.com, c @ company2.com "...
I know that this code is wrong, I think that I am missing a group, but this illustrates the point. I am not sure of the syntax. Is it possible? Thanks for any help.
linq subquery
Keith May 18, '10 at 21:15 2010-05-18 21:15
source share