LINQ 版本的 TOP PERCENT [英] LINQ version of TOP PERCENT

查看:12
本文介绍了LINQ 版本的 TOP PERCENT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用百分比执行顶级(Take)linq 查询?T-SQL 应该是:

Is there a way to perform a top (Take) linq query using percentage? The T-SQL would have been:

SELECT TOP 20 PERCENT ...

但 LINQ 似乎只想要一个整数.

But LINQ seems to only want an int.

看来我得先数一数,然后再取.有什么建议吗?

It seems that I would have to do a count and then a take. Any suggestions?

推荐答案

本质上,您必须执行两次查询.您必须执行一次以获得计数,然后再次计算百分比(因为您将传递与等于 20% 的计数相对应的数字).

You would have to perform the query twice, in essence. You would have to perform it once to get a count, and then again to figure out the percentage (because you will pass the number that corresponds to the count that will equal 20%).

这篇关于LINQ 版本的 TOP PERCENT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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