Any()
用于判断集合中是否有元素满足某一条件;不延迟。(若条件为空,则集合只要不为空就返回True,否则为False)。 bool isValid = storeDB.Orders.Any(o => o.OrderId == id && o.Username == User.Identity.Name); Take(int n); var shops = (from u in storeDB.Shops where u.TitleShopValue > 0 orderby u.TitleShopValue descending select u).Take(8).ToList();取排前面的N个。
Contains();提供模糊查询 var shops = (from u in DB.Shops where u.Name.Contains(searchKey) orderby u.TitleShopValue descending select u).ToList(); var id =storeDB.Users.SingleOrDefault(u => u.UserName ==model.UserName).UserID;判断,返回bool类型 return (from s in roles from userrole in userroles where s.Equals(userrole) select s).Any(); 条件查询 IList<UserFollow> Follows = db.UserFollows.Where(o => o.UserId == userid).ToList(); 统计计数 var ageCoun = (from s in GetStudents() select s.Age).Count(a=>a>22);
Var Count = LDB.User.Count(o=>o.age == 23);