C# Linq Inner Join

后端 未结 3 1127
梦如初夏
梦如初夏 2021-01-11 18:20

I want to select the persons only who are having pets.

when I execute the query

var query = from p in people
                        join
                   


        
3条回答
  •  难免孤独
    2021-01-11 18:42

    Here's a different way to do it, adding only one line:

    var query = from p in people
                join pts in pets
                on p equals pts.Owner into grp
                where grp.Any()             // <--- added this
                select new {grp=grp,PersonName=p.FirstName};
    

    Here I select the groups, as you do, but I added one line that selects only the groups that contain at least one element, and ignore the rest.

提交回复
热议问题