c# - LINQ Sorting, Titles grouped by Author -


so currently, have program sorts list of books & authors. right now, outputting authors grouped title, meaning prints author's name & books he/she wrote. i'm trying reverse & have output book, & authors wrote book. appreciated.

// authors , titles of each book         // co-authored; group author         var titlesbyauthor =             author in dbcontext.authors             orderby author.lastname, author.firstname             select new             {                 name = author.firstname + " " + author.lastname,                 titles =                 book in author.titles                 orderby book.title1                 select book.title1             };          outputtextbox.appendtext("\r\n\r\ntitles grouped author:");          // display titles written each author, grouped author         foreach (var author in titlesbyauthor)         {             //display author's name             outputtextbox.appendtext("\r\n\t" + author.name + ":");             // display titles written author             foreach (var title in author.titles)             {                 outputtextbox.appendtext("\r\n\t\t" + title);             }         } 

please use linq group operator group books. here sample:

public void linq40()  {      int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };       var numbergroups =          n in numbers          group n n % 5 g          select new { remainder = g.key, numbers = g };       foreach (var g in numbergroups)      {          console.writeline("numbers remainder of {0} when divided 5:", g.remainder);          foreach (var n in g.numbers)          {              console.writeline(n);          }      }  } 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -