Is there a way to perform a top (Take) linq query using percentage? The T-SQL would have been:
SELECT TOP 20 PERCENT ...
But LINQ seems to only want an int.
It seems that I would have to do a count and then a take. Any suggestions?
var sum = (from temp in list select temp). Sum(); var percentage = from temp in list select temp/sum *100; the above one is optimized linq query. var percentage = from temp in list select (temp / list.
A query expression is a first-class language construct. It is just like any other expression and can be used in any context in which a C# expression is valid. A query expression consists of a set of clauses written in a declarative syntax similar to SQL or XQuery.
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%).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With