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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:48:29+00:00 2026-05-14T07:48:29+00:00

Context: ASP.NET MVC 2.0, C#, SQL Server 2008, IIS7 I have ‘scheduledMeetings’ table in

  • 0

Context: ASP.NET MVC 2.0, C#, SQL Server 2008, IIS7

I have ‘scheduledMeetings’ table in the database.
There is a one-to-many relationship: scheduledMeeting -> meetingRegistration
So that you could have 10 people registered for a meeting.
meetingRegistration has fields Name, and Gender (for example).

I have a “calendar view” on my site that shows all coming events, as well as gender count for each event.

At the moment I use Linq to Sql to pull the data:

var meetings = db.Meetings.Select(
    m => new {
        MeetingId = m.Id,
        Girls = m.Registrations.Count(r => r.Gender == 0),
        Boys = m.Registrations.Count(r=>r.Gender == 1)
    });

(actual query is half-a-page long)
Because there is anonymous type use going on I cant extract it into a method (since I have several different flavors of calendar view, with different information on each, and I don’t want to create new class for each).

Any suggestions on how to improve this?
Is database view is the answer?
Or should I go ahead and create named-type?

Any feedback/suggestions are welcome. My DataLayer is huge, I want to trim it, just don’t know how.

Pointers to a good reading would be good too.

  • 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-14T07:48:29+00:00Added an answer on May 14, 2026 at 7:48 am

    I’d extend your Meetings class by adding 2 properties:

    public partial class Meeting
    {
        #region Properties
        public int BoyCount { get; set; }
    
        public int GirlCount { get; set; }
        #endregion
    }
    

    With deferred loading:

    var items = db.Meetings.Select(
        m => new {
            Meeting = m,
            Girls = m.Registrations.Count(r => r.Gender == 0),
            Boys = m.Registrations.Count(r = >r.Gender == 1)
        }).ToList();
    
    items.ForEach(i =>
    {
        i.Meeting.BoyCount = i.Boys;
        i.Meeting.GirlCount = i.Girl;
    });
    
    List<Meeting> = items
        .Select(i => i.Meeting)
        .ToList();
    

    With eager loading, one of the solutions is to load Registrations with your Meeting entity:

    DataLoadOptions loadOptions = new DataLoadOptions();
    loadOptions.LoadWith<Meeting>(m = > m.Registrations);
    db.LoadOptions = loadOptions;
    

    In this case the partial class properties above are became getters:

    public partial class Meeting
    {
        #region Properties
        public int BoyCount 
        { 
            get
            {
                return this.Registrations
                    .Count(r => r.Gender == 1);
            }
        }
    
        public int GirlCount
        {
            get
            {
                return this.Registrations
                    .Count(r = > r.Gender == 0);
            }
        }
        #endregion
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Context: ASP.NET MVC 2.0, Linq-to-Sql, .Net 3.5, IIS7, MS SQL 2008 I'm working on
I have a table ContentHistory in a SQL Server 2008 database with a column
I am implementing a SaaS application using ASP.Net MVC 2 and SQL Server database.
Setting up ASP.net MVC with Linq2SQL or Entity Framework's context to have scaffolding work
I am working in ASP.Net MVC 1.0 and SQL Server 2000 using Entity Framework.
I'm working on an asp.net-mvc application. The linq data context is being passed into
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I'm really new to both ASP.NET MVC and the MVC pattern generally. For context,
I have an ASP.NET MVC 2 application with a custom StructureMap controller factory to
I have created an extension method for an ASP.NET MVC ViewPage, e.g: public static

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.