码迷,mamicode.com
首页 > 其他好文 > 详细

EF selection expression 与 Linq备忘

时间:2014-09-30 19:10:49      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   sp   div   c   on   

一、左连接查询

var query =
    people.GroupJoin(pets,
                     person => person,
                     pet => pet.Owner,
                     (person, petCollection) =>
                        new { OwnerName = person.Name,
                              Pet = PetCollection.Select( p => p.Name )
                                                 .DefaultIfEmpty() }
                    ).ToList();

var query = (from person in context.People
             join pet in context.Pets on person equals pet.Owner
             into tempPets
             from pets in tempPets.DefaultIfEmpty()
             select new { OwnerName = person.Name, Pet = pets.Name })
            .ToList();

EF selection expression 与 Linq备忘

标签:style   blog   color   io   ar   sp   div   c   on   

原文地址:http://www.cnblogs.com/cxp9876/p/4002280.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!