Solved

into dateGroup  LINQ statement ???

Posted on 2014-02-21
3
296 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 62

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 62

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now