请问该如何用LINQ的lambda表达式写出Select语句中的NOT IN 语句?

如何用LINQ的lambda表达式写出Select语句中的NOT IN

青春有我
浏览 478回答 2
2回答

慕侠2389804

List<int> myint = new List<int>();myint.Add(3);myint.Add(4);myint.Add(5);myint.Add(6);List<int> myint2 = new List<int>();myint2.Add(3);myint2.Add(4);var resint = myint.Except(myint2);foreach (int item in resint){Console.Write(item);}

缥缈止盈

使用 LINQ 查询表达式IEnumerable<SelectListItem> stores =from store in database.Storeswhere store.CompanyID == curCompany.IDselect new SelectListItem { Value = store.Name, Text = store.ID };ViewBag.storeSelector = stores;或使用 LINQ 扩展方法和 lambda 表达式IEnumerable<SelectListItem> stores = database.Stores.Where(store => store.CompanyID == curCompany.ID).Select(store => new SelectListItem { Value = store.Name, Text = store.ID });ViewBag.storeSelector = stores;
打开App,查看更多内容
随时随地看视频慕课网APP