LINQ DefaultIfEmpty Generation Operator

By Peter Bromberg

The DefaultIfEmpty operator supplies a default element for an empty sequence. One use of this operator is when performing outer joins on two sequences.

var results = (from u in rv.tbl_user
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();  

LINQ DefaultIfEmpty Generation Operator  (1028 Views)