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

查看:79
本文介绍了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天全站免登陆