Last active
September 28, 2015 09:22
-
-
Save foyzulkarim/56295d655402f6b10d61 to your computer and use it in GitHub Desktop.
Complex LINQ Group by Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is the type of the variable 'histories' in the above gist?