Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. grouping by more than 1 column

grouping by more than 1 column

Scheduled Pinned Locked Moved LINQ
csharpdatabaselinqhelptutorial
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    balaji t
    wrote on last edited by
    #1

    hi all, Can any1 help me as to how to group by more than 1 column using LINQ.Ive succeeded grouping with 1 column as follows. DC1DataContext dc = new DC1DataContext(); var Fetch = from e in dc.employee join d in dc.dept on e.emp_ID equals d.emp_ID group e by e.emp_ID into g select new { EmpID = g.Key, Total= g.Count(), }; now i want to group by empname also..this is my original query select e.emp_id,emp_name,count(*) as total from employee e ,dept d where e.emp_id = d.emp_id group by e.emp_id,emp_name Thanx in advance

    T.Balaji

    B 1 Reply Last reply
    0
    • B balaji t

      hi all, Can any1 help me as to how to group by more than 1 column using LINQ.Ive succeeded grouping with 1 column as follows. DC1DataContext dc = new DC1DataContext(); var Fetch = from e in dc.employee join d in dc.dept on e.emp_ID equals d.emp_ID group e by e.emp_ID into g select new { EmpID = g.Key, Total= g.Count(), }; now i want to group by empname also..this is my original query select e.emp_id,emp_name,count(*) as total from employee e ,dept d where e.emp_id = d.emp_id group by e.emp_id,emp_name Thanx in advance

      T.Balaji

      B Offline
      B Offline
      balaji t
      wrote on last edited by
      #2

      hi all, i got the solution.. we shud give like this.. var Fetch = from e in dc.employee join d in dc.dept on e.emp_ID equals d.emp_ID group e by new {e.emp_ID,e.empname} into g select new { EmpID = g.Key.emp_ID, Empname= g.key.empname, Total= g.Count() };

      T.Balaji

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups