首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

ling 查询 基础 group by解决办法

2012-10-14 
ling 查询 基础 group byC# code (from p in db.PlayedVideos group p.ID by p.VideoID into g select new

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

热点排行