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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:02:40+00:00 2026-05-12T16:02:40+00:00

I am building my first few projects with ASP.NET MVC, and I have a

  • 0

I am building my first few projects with ASP.NET MVC, and I have a list of items that come from 2 tables.

Using the nerd dinner example, this is my problem.

Lets say I want to have all the dinners, with all the rsvp information in a list on one page.

So it would go

dinnername1

rsvp1 rsvp2

dinnername2

rsvp1 rsvp2 rsvp3

Currently I’m using this linq to bring what I think is the correct data back

public IQueryable<Dinner> GetAllUserDinnersAndRSVPs(string userId)
    {
        return from dinner in db.Dinner
               from rsvp in db.RSVP
               where dinner.userId == userId
               where rsvp.userId == userId
               select dinner;
    }

This I think is bringing back the correct number of results, but because I am only bringing back the dinner type, the rsvp information doesn’t show up in the collection.

So I think what I need to do is build a custom Model (class?) which will store all the info from the dinners table and the rsvp table, called something like DinnerTask.cs

This will basically just have a load of properties for each of the columns of both of the tables, and will mean that I can sort the entire list in c# before using a foreach to render out to the page.

I guess the defination of the class would be something like this.

public class DinnersAndRSVPsModel
{


        public int DinnerId { get; set; }
        public string DinnerName { get; set; }
        rest of fields for table 1......

        public int RSVPId { get; set; }
        public int RSVPInfo { get; set; }
        rest of fields for table 2.......
}

I’m asking this question because I think this seems like I am doing this wrong, and hopefully someone can point me in the right direction for working with data like this.

I would really appreciate any examples of this including the linq query, class defination etc… Bonus points if you could help me with any of the sorting as well, but I think I should be able to work that out.

Thank you for any help.

  • 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-12T16:02:40+00:00Added an answer on May 12, 2026 at 4:02 pm

    I read Linq in Action to help me get to this solution, and then this post also helped me greatly

    How do I group data in an ASP.NET MVC View?

    The way I got this to work was by adding a custom type (class)

    (excuse the bad naming conventions)

    public class DinnerAndRsvpName
    {
        public string Dinnername { get; set; }
        public string RSVPname { get; set; }
    
    }
    

    I then rewrite the linq query to this

    return from dinner in db.Dinner
                   join rsvp in db.RSVPs on Dinner.id equals RSVP.DinnerId into DinnerRsvp
                   where dinner.userId == userId
                   from rsvp in DinnerRsvp.DefaultIfEmpty()
                   select new DinnerAndRsvpName
                   {
                       Dinnername = goal.name,
                       RSVPname = rsvp == default(RSVPs) ? "No RSVP" : rsvp.name
    
                   };
    

    and then changed the model view to this

    <ul>
     <% foreach (var group in Model.GroupBy(item => item.Dinnername)) { %>
    
    <li><%= Html.Encode(group.Key) %>
     <ul>
    
     <% foreach (var item in group) { %>
       <li><%= Html.Encode(item.RSVPname) %></li>  
     <% } %>
    
     </ul>
    

      <% } %>
    

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

Sidebar

Related Questions

I'm building my first ASP.NET MVC website, and I'm trying to figure out how
I am building an ASP.Net MVC 3 web application using Entity Framework 4.1 with
I'm building an ASP.NET MVC site where I want to implement jQuery AJAX calls
I am building my first ASP.Net web application project in VS2010. The site has
I have been using SilkJS for a few hobby projects of mine. So far,
I'm building my first website with rails,it consists of a blog, a few static
Building my first SL MVVM application (Silverlight4 RC) and have some issues i don't
I'm building my first Android image, i noticed that compiling a new kernel is
I'm building my first jquery mobile site and have run into a problem. When
My team is building our first significant Silverlight application, using a 3 layered architecture

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.