Solved

into dateGroup  LINQ statement ???

Posted on 2014-02-21
3
301 Views
Last Modified: 2016-02-10
I was wondering if I could get an explanation bellow....  not sure what it mean into dateGroup or what this querry mean bellow....

 var data = from student in db.Students
               group student by student.EnrollmentDate into dateGroup
               select new EnrollmentDateGroup()
               {
                   EnrollmentDate = dateGroup.Key,
                   StudentCount = dateGroup.Count()
               };
    return View(data);
0
Comment
Question by:yguyon28
  • 2
3 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39877853
Hi yguyon28;

Please see the comments in the code.

// The db is most likely a object of some DataContext such as a database
// This first line will Iterate through the Students table, Each iteration 
// will put a single student record into student.
var data = from student in db.Students
           // This next line will group the student records from the Students table 
           // into groups which have the same EnrollmentDate, so all Students within 
           // a single group will have the same in EnrollmentDate and dateGroup is 
           // an object that will contain all the groups.
           group student by student.EnrollmentDate into dateGroup
           // The EnrollmentDateGroup is a class with at miniumn two public properties, 
           // EnrollmentDate and StudentCount. One of these classes is created for each 
           // group in dateGroup. 
           select new EnrollmentDateGroup()
           {
               // The value of Key is the identification of each group which is 
               // EnrollmentDate
               EnrollmentDate = dateGroup.Key,
               // the value in StudentCount is the total number of students in a 
               // particular group.
               StudentCount = dateGroup.Count()
           };
           
// This seems to be an ASP MVC application so the results of the above query
// is being returned to the view for the function.           
return View(data);

Open in new window

0
 

Author Closing Comment

by:yguyon28
ID: 39878049
Thank u for the answer and ur time.
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 39878054
Not a problem yguyon28, glad to help.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question