读书人

ling 查询 基础 group by解决办法

发布时间: 2012-10-14 14:55:08 作者: rapoo

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);            }        }    }} 

读书人网 >asp.net

热点推荐