title: A good(elegant) way to retrieve records with counts
body: <p>Context: ASP.NET MVC 2.0, C#, SQL Server 2008, IIS7</p>
  
  <p>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).</p>
  
  <p>I have a "calendar view" on my site that shows all coming events, as well as gender count for each event.</p>
  
  <p>At the moment I use Linq to Sql to pull the data:</p>
  
  <pre><code>var meetings = db.Meetings.Select(
      m =&gt; new {
          MeetingId = m.Id,
          Girls = m.Registrations.Count(r =&gt; r.Gender == 0),
          Boys = m.Registrations.Count(r=&gt;r.Gender == 1)
      });
  </code></pre>
  
  <p>(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).</p>
  
  <p>Any suggestions on how to improve this?
  Is database view is the answer?
  Or should I go ahead and create named-type?</p>
  
  <p>Any feedback/suggestions are welcome. My DataLayer is huge, I want to trim it, just don't know how.</p>
  
  <p>Pointers to a good reading would be good too.</p>