LINQ Inner-Join vs Left-Join

前端 未结 6 1120
轮回少年
轮回少年 2020-11-27 13:36

Using extension syntax I\'m trying to create a left-join using LINQ on two lists that I have. The following is from the Microsoft help but I\'ve modified it to show that the

6条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 14:31

    If you actually have a database, this is the most-simple way:

    var lsPetOwners = ( from person in context.People
                        from pets in context.Pets
                            .Where(mypet => mypet.Owner == person.ID) 
                            .DefaultIfEmpty()
                         select new { OwnerName = person.Name, Pet = pets.Name }
                       ).ToList();
    

提交回复
热议问题