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 Query

More Query from same tag