当前位置: 代码迷 >> ASP.NET >> ling 查询 基础 group by解决办法
  详细解决方案

ling 查询 基础 group by解决办法

热度:10648   发布时间:2013-02-25 00:00:00.0
ling 查询 基础 group by
C# code
 (from p in db.PlayedVideos group p.ID by p.VideoID into g select new {VideoID = g.Key, ID = g.Max()})


------解决方案--------------------------------------------------------
C# code
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication1{    class PlayedVideo    {        public int id { get; set; }        public int videoid { get; set; }    }    class Program    {        static void Main(string[] args)        {            List<PlayedVideo> playedVideos = new List<PlayedVideo>()            {                new PlayedVideo() { id = 1, videoid = 0 },                new PlayedVideo() { id = 2, videoid = 0 },                new PlayedVideo() { id = 3, videoid = 0 },                new PlayedVideo() { id = 4, videoid = 1 },                new PlayedVideo() { id = 5, videoid = 1 },                new PlayedVideo() { id = 6, videoid = 1 }            };            var query = from x in playedVideos group x.id by x.videoid into g select new { VideoID = g.Key, ID = g.Max() };            foreach (var item in query)            {                Console.WriteLine("VideoID {0}, ID {1}.", item.VideoID, item.ID);            }        }    }}
  相关解决方案