Solved

into dateGroup  LINQ statement ???

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

20 Experts available now in Live!

Get 1:1 Help Now