TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
محمد صلاح الدين
NA
75
3.7k
Group by Inside Group by Using EntityFramwork in Mvc5
Dec 13 2018 4:30 AM
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
Reply
Answers (
2
)
How to Disbled true ajax cascading dropdown list After load
Convert Image Into fixed Dimensions