Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I perform a SelectMany in C# query syntax using a many-to-many joining table?

I have the following c# statement that via EF generates exactly what I'm looking for but am curious as to how I'd write this with query syntax:

var dealers = this.Dealers
    .SelectMany (d => d.Brands, (d, col) => new { Name = d.Name, Brand = col.Name, StatusId = d.StatusId })
    .Where (d => d.StatusId == 1);
like image 206
James Alexander Avatar asked Oct 05 '11 14:10

James Alexander


1 Answers

var dealers = from d in Dealers
              from col in d.Brands
              where d.StatusId == 1
              select new { Name = d.Name, 
                           Brand = col.Name, 
                           StatusId = d.StatusId };
like image 187
Daniel Hilgarth Avatar answered Sep 27 '22 20:09

Daniel Hilgarth