score:0
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);
}
Source: stackoverflow.com
Related Query
- How to convert decimal? to decimal while using LINQ with a stored procedure
- Convert stored procedure to LINQ
- how to convert the stored procedure to Linq
- Would like to convert complex Linq query to Stored Procedure
- convert the paramater's date type to varchar , of stored procedure in linq query
- Convert stored procedure to Linq statement
- Can't convert stored procedure to Linq expression successfully
- Reuse stored procedure result in linq to sql in Code First
- Convert string[] to int[] in one line of code using LINQ
- Is it Possible to call a Stored Procedure using LINQ in LINQPad?
- Stored Procedure return values with linq data context
- Getting stored procedure output parameter with LINQ and Entity Framework
- LINQ calling a Stored Procedure is slow
- LINQ on a DataTable IN a CLR Stored Procedure
- Lost decimal precision and scale using LINQ and stored procedure with output parameters
- Linq Stored Procedure Timeout but SSMS Quick
- Linq - interrupt execution of stored procedure
- LINQ to SQL: Stored Procedure Results
- Linq stored procedure to return XML
- C# LINQ Stored Procedure
- LINQ Source Code Available
- Executing stored procedure using linq in c#
- Cannot convert source type to target type List<KeyValuePair> Linq
- How to use a system stored procedure in LINQ to SQL
- What are the advantages using LINQ than stored procedure
- convert foreach loop to linq code
- Performance of Linq on entity framework vs SQL stored procedure
- Return newly inserted row id from stored procedure using LINQ toSQL
- Linq Stored Procedure Issue- Returning an int
- creating Linq to sqlite dbml from DbLinq source code
More Query from same tag
- Linq To Sql Conversation In Wcf Service
- LINQ query skips debug and does not execute next line
- Query an XDocument Query doesn't work when element/root has Namespace as atribute
- Multiple records using Find method in Entity Framework by passing list of primary keys
- Linq: adding conditions to the where clause conditionally
- Create a list from pairwise comparison
- Uppercase a List of object with LINQ
- LINQ Expressions Creating an Array with different object types
- How do you do alias in Select method (LINQ)
- What is the difference between Object and Context in Linq/Entity Framework
- What it the easiest way to make LINQ to process all collection at once?
- How to convert a List<T> into a Dictionary<> using a T property as key and rest of properties as List<T1>
- trim away duplicates using Linq
- DefaultIfEmpty issues with linq statement
- How to Update Two Tables using LINQ in ASP.NET MVC 4 Web Applications
- C# IEnumerable.Count() throws IndexOutOfRangeException
- How to replace "-" with empty space when columns are null in LINQ
- Automapping double nested IEnumerable
- Abstracting actions on different tables in Entity Framework
- Concatenating 2 objects into a dictionary value
- Linq join returning parent even when child is null
- MVC search a LINQ query
- Select vs Select new in linq
- get values from nested Dictionary using LINQ. Values of Dictionary are list of lists
- Linq - select N-level childs from hierarchy parents
- LINQ to SQL Mapping From Money to Double
- LINQ .Take() after .Distinct() issue
- How to write LINQ query that selects a property which is a string concat of a collection of a nested entity properties?
- How to check list A contains any value from list B?
- Linq: How to calculate the sales Total price and group them by product