Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need a help with LINQ.

I have a SQL table with schema as follows:

| EmployeeName | Amount | DatePaid |

| Robert Gary | 1200 | 12-08-2014 |

| Tom Michel | 1100 | 12-07-2014 |

| Tom Michel | 500 | 07-07-2014 |

| Robert Gary | 1200 | 05-08-2014 |

| Robert Gary | 1200 | 28-11-2012 |

| Robert Gary | 1200 | 12-08-2013 |


----------


I want to group the output and display on the UI (Web Form html table) as follows:

Robert Gary:

| Amount | DatePaid |

| 1200 | 12-08-2014 |

| 1200 | 05-08-2014 |

| 1200 | 28-11-2012 |

| 1200 | 12-08-2013 |


Tom Michel

| Amount | DatePaid |

| 1100 | 12-07-2014 |

| 500 | 07-07-2014 |


Is there a way i can achieve it through LINQ or some SQL statement to manipulate data.
Appreciate any help.

Thank You Very Much!
Posted

1 solution

Try this

var groupedElement = from element in Orders
                     group element by element.EmployeeName into elementGroup
                     select new {name = elementGroup.key , details= elementGroup }



"Order" contains all the Name, amount, DatePaid details
 
Share this answer
 
v2
Comments
Adil S 4-Oct-14 14:07pm    
Hi Shemeemsha, Thanks a lot. Thats exactly what i was looking for.
Although not being very good with LINQ. Im unable to traverse through 'groupedElement' variable. Please can you elaborate how can I achieve that.

Thanks in Advance.
Shemeemsha (ഷെമീംഷ) 4-Oct-14 15:05pm    
Hello Adil A Shaikhl...
Go through this link..
http://msdn.microsoft.com/en-us/library/bb546139.aspx

Use your Visual Studio Debugger for getting the variable structure of groupedElement . Using that you can explore the data easily..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900