You could wrap your logic into one query totals. AddRange(entityContext. ItemVotes .
Where(iv => iv. Vote >= 1 && iv. Vote iv.
Vote) . OrderBy(grp => grp. Key) .
Select(grp => grp.Count()) (This code is untested and could be way off base but just throwing out an idea).
You could wrap your logic into one query totals. AddRange(entityContext. ItemVotes .
Where(iv => iv. Vote >= 1 && iv. Vote iv.
Vote) . OrderBy(grp => grp. Key) .
Select(grp => grp.Count()); (This code is untested and could be way off base but just throwing out an idea).
Looks promising, but kvp. Values does not exist. – Kon Apr 11 at 14:11 edited to make it work and more clear – Jimmy Apr 11 at 14:47 Getting close.
But if any of the votes have a count of zero, they are not in the list. For example, my original query returns a list: 0, 1, 3, 0. But your list returned is just: 1, 3.
Took out Where clause and no change. – Kon Apr 11 at 19:54 Well, this doesn't yield the exact result I was looking for, but it's close enough to get someone on the right path. Thanks.
– Kon Apr 110 at 22:09.
In LINQ the .Count() method forces execution of a query. If you need 4 different totals there is no other way to produce that in one statement.
You might be surprised at the results, I know I was. And I gained a deep respect for the devs on the SQL server team who seem to be doing quite an excellent job at making what looks like a sub-optimal query perform just the same. I'd be interested in hearing if your experience differs from mine; I stopped looking for ways to change the generated queries because for every query I tried looking at, there was no real difference in performance.
My last statement isn't entirely true, there are definitely N+1 situations that you have to watch out for, and any batch operations (updates, deletes, and inserts of multiple records at the same time) aren't going to be even close in performance to writing a query by hand due to the nature of working with individual records. But the extraneous extents essentially get stripped out by the SQL Server query optimizer.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.