实体框架取前10行 [英] Entity Framework fetch Top 10 rows

查看:100
本文介绍了实体框架取前10行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆