0

The following is my linq query

  var meetingIndividualQuery = meetingsList.SelectMany(o => o.Attendies.Distinct().Where(x => x.CompanyId == company.CompanyId));

I have the following class

public class Meetings
    {
        public string IndustryCouncil { get; set; }
        public string MeetingType { get; set; }
        public string MeetingDescription { get; set; }
        public string MeetingDate { get; set; }
        public string MeetingHours { get; set; }
        public string MeetingHourlyValue { get; set; }
        public string MeetingTotal { get; set; }
        public List<Individual> Attendies { get; set; }
    }

With the above query I am getting the correct list of individaul but how I can I use the same query with the same condition to retrieve the list of Meetings. Can you please provide me any code

Shailesh Jaiswal
  • 3,606
  • 13
  • 73
  • 124
  • 2
    What exactly do you mean by "list of meetings"? Every property starting with `Meeting`? – phipsgabler May 25 '12 at 10:15
  • Meetings What? `MeetingType` or `MeetingDescription` or `MeetingDate` or `MeetingHours` or `MeetingHourlyValue` or `MeetingTotal`? What? Not pretty sure what is asked here? – Nikhil Agrawal May 25 '12 at 10:16
  • I want the List where Meetings is the class with the same condition meetingsList.SelectMany(o => o.Attendies.Distinct().Where(x => x.CompanyId == company.CompanyId)) – Shailesh Jaiswal May 25 '12 at 10:18
  • Probably there are not many differend companyIds . Not sure why you used distinct in the first place – isioutis May 25 '12 at 10:19
  • Also see this question http://stackoverflow.com/questions/958949/difference-between-select-and-selectmany – Mike Two Aug 04 '12 at 19:04

1 Answers1

2

Following query will return list of meetings, which have at least one attendee with provided company id:

var query = meetingsList.Where(m => m.Attendies.Any(i => i.CompanyId == company.CompanyId));

You can also apply Distinct to Attendies before verifying Any

Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459