Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3801582
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:04:21+00:00 2026-05-19T14:04:21+00:00

I’m trying to create a linq expression whereby I can COUNT the number of

  • 0

I’m trying to create a linq expression whereby I can COUNT the number of event comments as well as SUM the number of Votes. Here’s what I’ve got, but I’m not getting the appropriate results.

My example is done in VB.Net, but I can deal with examples in C# as well.

    Public Function GetHotEvents(ByVal skip As Integer) As List(Of Domain.Event) Implements IEventService.GetHotEvents
        ''# Our order by sequence just takes the number of votes and multiplies
        ''# it by two. Then takes the number of comments and adds it to the
        ''# vote count.  This way up-voted events will climb to the top while
        ''# down-voted events will fall to the bottom.  Comments also add to
        ''# the "hotness" of the event.
        Return _EventRepository.Read() _
            .Where(Function(e) e.EventDate >= Date.Today) _
            .OrderBy(Function(e) (((e.EventVotes.Sum(Function(s) s.Vote)) * 2) + (e.Comments.Count))) _
            .Skip(skip) _
            .Take(5) _
            .ToList()
    End Function

What I’ve done to test this is have ZERO comments on all events, and upvote ONE event. That event “should” float to the top, but it’s not there.

Any help would be greatly appreciated.

edit

I’ve tried building the expression in LinqPad but unfortunately it threw an error (note: this error doesn’t get thrown in my code)

Overload resolution failed because no
accessible ‘OrderBy’ can be called
with these arguments:
Extension method ‘Public Function OrderBy(Of TKey)(keySelector As
System.Linq.Expressions.Expression(Of
System.Func(Of LINQPad.User.Events,
TKey))) As
System.Linq.IOrderedQueryable(Of
LINQPad.User.Events)’ defined in
‘System.Linq.Queryable’: ‘Comments’ is
not a member of ‘LINQPad.User.Events’.
Extension method ‘Public Function OrderBy(Of TKey)(keySelector As
System.Linq.Expressions.Expression(Of
System.Func(Of LINQPad.User.Events,
TKey))) As
System.Linq.IOrderedQueryable(Of
LINQPad.User.Events)’ defined in
‘System.Linq.Queryable’: Data type(s)
of the type parameter(s) cannot be
inferred from these arguments.
Specifying the data type(s) explicitly
might correct this error.
Extension method ‘Public Function OrderBy(Of TKey)(keySelector As
System.Func(Of LINQPad.User.Events,
TKey)) As
System.Linq.IOrderedEnumerable(Of
LINQPad.User.Events)’ defined in
‘System.Linq.Enumerable’: ‘Comments’
is not a member of
‘LINQPad.User.Events’.
Extension method ‘Public Function OrderBy(Of TKey)(keySelector As
System.Func(Of LINQPad.User.Events,
TKey)) As
System.Linq.IOrderedEnumerable(Of
LINQPad.User.Events)’ defined in
‘System.Linq.Enumerable’: Data type(s)
of the type parameter(s) cannot be
inferred from these arguments.
Specifying the data type(s) explicitly
might correct this error.

edit 2

Here’s the generated SQL

DECLARE @p0 Int = 2    

SELECT *
FROM [dbo].[Events] AS [t0]
ORDER BY (((
    SELECT SUM([t1].[Vote])
    FROM [dbo].[EventVotes] AS [t1]
    WHERE [t1].[EventID] = [t0].[ID]
    )) * @p0) + ((
    SELECT COUNT(*)
    FROM [dbo].[Comments] AS [t2]
    WHERE [t2].[EventID] = [t0].[ID]
    ))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T14:04:22+00:00Added an answer on May 19, 2026 at 2:04 pm

    Did you mean OrderByDescending? 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.