« Home | Querying the DataTable in .Net » | Converting DataView into DataTable » | Deleting TFS Project »

SQL in .net Using LINQ



Assume that you have a table with a datetime field. You need to get the result grouped by both month and

 year and also you need number of records that falls into the grouped category.

This can be done easily with the help of LINQ.

####Code Starts####

var grouped = from p in groups

group p by new { month = p.Create.Month,year= p.Create.Year } into d

select new { dt = string.Format("{0}/{1}",d.Key.month,d.Key.year), count = d.Count() };
 
####Code Ends####
 
Thats is , you got the result.
 
Happy Coding..

Post a Comment

Translate

About me

Narayanan
Senior Software Engineer
Microsoft Certified Professional Developer
MCPD

Chat

Visitors