Defaultifempty seems to work in linq to entities

Posted by Rand on Stack Overflow See other posts from Stack Overflow or by Rand
Published on 2010-03-21T11:04:16Z Indexed on 2010/03/21 11:11 UTC
Read the original article Hit count: 548

I'm new to linq and linq to entities so I might have gone wrong in my assumptions, but I've been unknowingly trying to use DefaultIfEmpty in L2E.

For some reason if I turn the resultset into a List, the Defaultifempty() works I don't know if I've inadvertantly crossed over into Linq area. The code below works, can anyone tell me why? And if it does work great, then it'll be of help to other people.

               var results = (from u in rv.tbl_user 
                    .Include("tbl_pics") 
                    .Include("tbl_area") 
                    .Include("tbl_province") 
                    .ToList() 
                    where u.tbl_province.idtbl_Province == prov 
                   select new { u.firstName, u.cellNumber, 
                   u.tbl_area.Area, u.ID,u.tbl_province.Province_desc, 
                                pic = (from p3 in u.tbl_pics 
                                       where p3.tbl_user.ID == u.ID 
                    select p3.pic_path).DefaultIfEmpty("defaultpic.jpg").First() 
                                           }).ToList(); 

© Stack Overflow or respective owner

Related posts about linq-to-entities

Related posts about defaultifempty