日期:2014-05-20 浏览次数:21045 次
News[] table = new News[] { new News{_id = 1000,_type = 1, _display = 5}, new News{_id = 1001,_type = 1, _display = 5}, new News{_id = 1002,_type = 1, _display = 5}, new News{_id = 1003,_type = 1, _display = 5}, new News{_id = 1004,_type = 2, _display = 4}, new News{_id = 1005,_type = 2, _display = 5}, new News{_id = 1006,_type = 2, _display = 5}, new News{_id = 1007,_type = 2, _display = 4}, new News{_id = 1008,_type = 3, _display = 5}, new News{_id = 1009,_type = 3, _display = 4} }; News[] result = table.Where(o => o._display == 5) .Where(o => o._type == 1 || o._type == 2) .ToArray<News>(); foreach (News item in result) Console.WriteLine("{0}-{1}-{2}", item._id, item._type, item._display);
------解决方案--------------------
//可以 分组 var query= from n in Model.Context.News group n by n.Type into g where g.key==1 ||g.key==2 select g.Where(w=>w.Display==5).Take(3); var query1 = Model.Context.News.GroupBy(g => g.Type ) .Where(g => g.Key == 1 || g.Key == 2) .Select(s => s.Where(w => w.Display==5).Take(3));
------解决方案--------------------