Hi guys I am trying I try to bring the count for each male and female by age As in the table
I was able to calculate all ages but I can not count the ages as boys and girls like this
here is my code in controller
- public ActionResult AllCuont()
- { var query = (from t in db.Pations
- let range = (
- t.Age>= 1 && t.Age < 5 ? "age from 1 to 4" :
- t.Age >= 5 && t.Age < 15 ? "age from 5 to 14" :
- t.Age >= 15 && t.Age < 25 ? "age from 15 to 24" :
- t.Age >= 25 && t.Age < 45 ? "age from 25 to 44" : ""
- ) group t by range into g
- select new UserRange { AgeRange = g.Key, Count = g.Count() }).ToList();
- query.Add(new UserRange() { AgeRange = "Sum",Count = query.Sum(c => c.Count) });
- ViewBag.UserData = query; return View(db.Pations); }
and my modal pation like this
- namespace app.Models
- {
- public class Pation
- {
- [Key]
- public int Id { get; set; }
- public string PationName { get; set; }
- public int Age { get; set; }
- public Sex Sex { get; set; }
- public ApplicationUser User { get; set; }
- }
- public enum Sex
- {
- boys,
- girls,
- }
- }
and this is table for count my value
- public class UserRange
- {
- public string AgeRange { get; set; }
- public int Count { get; set; }
- }
my question is how Display count for each male and female by age