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?
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?
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%).
I don't think there's anything built into LINQ to SQL. You could do it with a stored procedure. I don't like that much, unless you happen to be using a procedure anyway, but it's probably better than doing it with two separate queries.