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

LINQ

时间:2015-09-19 15:10:55      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

 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         }

 

LINQ

标签:

原文地址:http://www.cnblogs.com/leee/p/4821469.html

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