标签:
1 public ActionResult TestLinq() 2 { 3 // 内连接 4 var resUser = from user in db.UserInfor 5 join answer in db.Answer on user.ID equals answer.UserInforID 6 where user.ID > 10 && user.ID < 20 7 select new { user.ID, user.UName, answer.AnswerDespression }; 8 9 //外连接 10 var resUserLeftOut = from user in db.UserInfor 11 join answer in db.Answer on user.ID equals answer.UserInforID into a 12 from answerRes in a.DefaultIfEmpty() 13 where user.ID > 10 && user.ID < 20 14 select new { user.ID, user.UName, answerRes.AnswerDespression }; 15 16 17 var resLinq = from u in db.UserInfor 18 select u; 19 20 var resLambda = db.UserInfor.Where(u => u.ID > 10 && u.ID < 20) 21 .Select(u => new { u.ID, u.UName, u.UPassword }); 22 return View(); 23 }
标签:
原文地址:http://www.cnblogs.com/leee/p/4821469.html