实体框架取前10行 [英] Entity Framework fetch Top 10 rows
问题描述
我在SQL数据库3表
tblVideos
VideoID int PK
Title varchar(100)
Decription varchar(100)
tblTags
TagID int PK
TagText varchar(100)
tblVideosToTags
VideoID int PK, FK to Videos
TagID int PK, FK to Tags
在实体框架(V6-最新-每晚建造)我有2班视频
和标签
与许多一对多的关系。我需要建立一个LINQ的实体或LINQ to SQL查询满足以下条件的帮助:
In Entity Framework (v6-latest-nightly-build) I have 2 classes Video
and Tag
with many-to-many relationships. I need a help with building a LINQ to Entities or LINQ to SQL query which meets following conditions:
十大记录:从标签,这是最常用的。所以可能是一些求和/计数/编组需要
Top 10 records from Tags, which is mostly used. So probably some summing/count/grouping needed
推荐答案
如果你想找到的前10名影片数最多的标签,你可能会发现更容易,但事实上,你想做的事,现在是一模一样。你只需要前10名的标签数最多的影片。使用此:
If you wanted to find the top 10 Videos with the most number of Tags, you would probably find it easier, but in fact what you want to do now is exactly the same. You just need the top 10 Tags with the most number of Videos. Use this:
var mostUsedTags = db.Tags.OrderByDescending(t => t.Videos.Count).Take(10);
这篇关于实体框架取前10行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!