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 6085403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:38:06+00:00 2026-05-23T11:38:06+00:00

I have 2 simple entities Activity ActivityViews Activity Views has 2 properties ActivityID and

  • 0

I have 2 simple entities

  1. Activity
  2. ActivityViews

Activity Views has 2 properties ActivityID and DateTime. This entity allows me to see everytime an Activity was accessed.

I now want to write a LinqToEntity query that returns a list of Activities in descending order of how many times they have been viewed.

So far I have come up with this

  var activities= ((from a in db.Activities
                    join av in db.ActivityViews on a.ID equals av.Activity.ID
                    group a by new { a } into g
                    select new { g, No = g.Count() }).OrderByDescending(x => x.No)).Select(x => x.g).ToList();

It kind of works but its returning a list of annonymous types and I want to get a back a list of activity types. I dont want to return the count of views just for it to be ordered by them.

Edit : I take that back what I have doesnt work at all, if there are now ActivityViews for an Activity nothing gets returned.

  • 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-23T11:38:06+00:00Added an answer on May 23, 2026 at 11:38 am

    Basically when you group whatever you group by is the key, so if you just select the key you will get what you need.

    Here would be a solution to it.

    var activities= 
      (
        (
           from a in db.Activities
           join av in db.ActivityViews
             on a.ID equals av.Activity.ID
           group a by a  into g
           select new { 
              a = g.Key, 
              No = g.Count() }
           ).OrderByDescending(x => x.No)
      ).Select(x => x.a)
      .ToList();
    

    Working on simplifying this now.

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

Sidebar

Related Questions

I have a simple entity data model where I have two entities and a
CoreData beginner I have a simple problem with CoreData. My model has two entities,
I have this simple situation: @Entity public class Customer{ @ManyToMany(fetch=FetchType.EAGER) @Cascade(CascadeType.SAVE_UPDATE) private List<Product> products=new
I have a very simple Country entity which I want to cache. This works
I have two simple entities: My\Entity\Coupon: type: entity table: coupon id: id: type: integer
I'm trying to use NHibernate for data access, and I have 2 simple entities
I have a simple @OneToMany between Person and Pet entities: @OneToMany(mappedBy=owner, cascade=CascadeType.ALL, fetch=FetchType.EAGER) public
I have mapped a simple entity, let's say an invoice using Fluent NHibernate, everything
I have a rather simple data model, but I have a centric entity called
In a simple inventory management app i have an activity to handle assigning equipment

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.