Skip to content

Instantly share code, notes, and snippets.

@foyzulkarim
Last active September 28, 2015 09:22
Show Gist options
  • Save foyzulkarim/56295d655402f6b10d61 to your computer and use it in GitHub Desktop.
Save foyzulkarim/56295d655402f6b10d61 to your computer and use it in GitHub Desktop.
Complex LINQ Group by Query
var histories = await (from history in db.Histories
group history by history.SurahId
into h
select h.ToList().Select(x => new MemorizedAyahViewModel()
{
Id = x.Id,
Surah = new SurahViewModel()
{
Index = x.Surah.Index,
Name = x.Surah.Name,
AyahCount = x.Surah.AyahCount
},
TotalSurahMemorized = x.TotalSurahMemorized,
TotalMemorized = x.AyahEnd - x.AyahStart + 1,
InitiallyMemorized = x.InitiallyMemorized
}).ToList()).ToListAsync();
public class MemorizedAyahViewModel
{
public string Id { get; set; }
public SurahViewModel Surah { get; set; }
public bool InitiallyMemorized { get; set; }
public bool TotalSurahMemorized { get; set; }
public int TotalMemorized { get; set; }
}
public class SurahViewModel
{
public string Name { get; set; }
public int Index { get; set; }
public int AyahCount { get; set; }
}
@foyzulkarim
Copy link
Author

What is the type of the variable 'histories' in the above gist?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment