score:0

Accepted answer
public JsonResult GetChart()
            {
                //int employeeId
              var Bug = db.Bugs.ToList<Bug>();
              var EmployeDetails = db.EmployeeDetails.ToList<EmployeeDetail>();
              var projects = db.Projects.ToList<Project>();

              var query = (from e in EmployeDetails
                           join b in Bug on e.EmployeId equals b.CreatedByID
                           join p in projects on b.ProjectId equals p.ProjectId
                           where e.EmployeId == 1
                           group new { p, b } by new
                           {
                               p.projectName
                           } into g
                           select new ChartModel
                           {
                               ProjectName = g.Key.projectName,                     

                               bug = g.Count()
                           }).ToList();
              return Json(query, JsonRequestBehavior.AllowGet);
}

i Got ...

score:1

Assuming you can pass the value in as a parameter to the method:

public JsonResult Getchart(int employeeId)
{
    var Bug = db.Bugs.ToList<Bug>();
    var EmployeeDetails = db.EmployeeDetails.ToList<EmployeeDetail>();
    var projects = db.Projects.ToList<Project>();

    var result = (from e in EmployeeDetails 
                  join b in Bug on e.EmployeeId equals b.CreatedByID
                  join p in projects on b.ProjectId equals p.ProjectId
                  where e.EmployeeId == employeeId   // <-- use the parameter here
                  group p by p.projectName into g
                  select new {
                     Project = g.Key,
                     Bug = g.Count() 
                     }
                 ).Take(50);
    return Json(result,JsonRequestBehavior.AllowGet);
}

BTW I intentionally corrected a few spellings of Employee

score:1

Is this what you need:

public JsonResult Getchart(int employeId)
  {
        var Bug = db.Bugs.ToList<Bug>();
        var EmployeDetails = db.EmployeeDetails.ToList<EmployeeDetail>();
        var projects = db.Projects.ToList<Project>();

       var result =   (from e in EmployeDetails 
                      join b in Bug on e.EmployeId equals b.CreatedByID
                      join p in projects on b.ProjectId equals p.ProjectId
                      where e.EmployeId == employeeId
                      group p.projectName
                     select new (p.projectName as Project ,count(b.CreatedByID) as Bug)).Take(50);
                       return Json(result,JsonRequestBehavior.AllowGet);
     }

Are you sure you want to do all of those "ToList<>()" calls? Once you call "ToList<>()", you bring all three of those tables into memory from the database. If they are large, that could be a performance issue.

score:1

If this is a controller action, you would probably want to pass the ID via the URL. Also, there is no need to call ToList on your tables before querying, do the query at the database and only pull down the results e.g.

public JsonResult GetChart(int employeeId)
{
    var query = (from e in db.EmployeeDetails
                join b in db.Bugs on e.EmployeeId equals b.CreatedById
                join p in db.Projects on b.ProjectId equals p.ProjectId
                where e.EmployeeId == employeeId
                group new {p, b} by new {
                    p.ProjectName
                } into g
                select new {
                    Project = g.Key.Name,
                    Bugs = g.Count()
                }).Take(50);
    return Json(query.ToList(), JsonRequestBehaviour.AllowGet);
}

Related Articles