using System.Collections.Generic;
public static void Main()
var db = FakeDbContext.Seed();
DumpTable(db.Hato, "All HATO Records");
DateTime startDate = new DateTime(2021,05,21);
DateTime endDate = new DateTime(2021,05,24);
DumpTable(db.Hato.Where(L => L.HatoRecDate >= startDate && L.HatoRecDate <= endDate), String.Format("HATO Between [{0:dd.MM.yyyy} - {1:dd.MM.yyyy}]", startDate, endDate));
var qLocation = (from L in db.Hato
where L.HatoRecDate >= startDate && L.HatoRecDate <= endDate
group L by L.HatoLocation into g
select new { HatoLocation = g.Key, count = g.Count() })
.OrderByDescending(o => o.count).ToList();
DumpTable(qLocation, "qLocation Grouping Results");
var l = qLocation[0].HatoLocation;
var c = qLocation[0].count;
Console.WriteLine("qLocation[0].HatoLocation: {0}", l);
Console.WriteLine("qLocation[0].count: {0}", c);
public class FakeDbContext
public static FakeDbContext Seed()
var db = new FakeDbContext();
db.Hato.Add(new Hato { HatoRecDate = new DateTime(2021,05,21), HatoLocation = "A" });
db.Hato.Add(new Hato { HatoRecDate = new DateTime(2021,05,21), HatoLocation = "A" });
db.Hato.Add(new Hato { HatoRecDate = new DateTime(2021,05,23), HatoLocation = "B" });
db.Hato.Add(new Hato { HatoRecDate = new DateTime(2021,05,24), HatoLocation = "A" });
db.Hato.Add(new Hato { HatoRecDate = new DateTime(2021,05,24), HatoLocation = "B" });
db.Hato.Add(new Hato { HatoRecDate = new DateTime(2021,05,20), HatoLocation = "A" });
db.Hato.Add(new Hato { HatoRecDate = new DateTime(2021,05,25), HatoLocation = "B" });
public ICollection<Hato> Hato = new HashSet<Hato>();
public DateTime HatoRecDate { get;set; }
public string HatoLocation { get;set; }
public static void DumpTable<T>(IEnumerable<T> table, string header = null)
if(!String.IsNullOrWhiteSpace(header))
Console.WriteLine("// {0}", header);
var columns = typeof(T).GetProperties();
Console.WriteLine("|{0}|", String.Join("|", columns.Select(c => c.Name)));
Console.WriteLine("|{0}|", String.Join("|", columns.Select(c => new String('-', c.Name.Length))));
foreach (T record in table)
foreach (var c in columns)
Console.Write("{0}|", c.GetValue(record, null));