我正在使用 MVC3 并且仍在学习 LINQ。我在尝试将查询转换为 LINQ to Entities 时遇到了一些麻烦。我想返回一个 Json 方法
我的存储过程
Create Procedure [dbo].[ResourceReports]
(
@EmployeeID int
)
as
begin
select p.projectName AS Projects, count( b.[CreatedByID]) AS Bugs
from [EmployeeDetails] e inner join [Bugs] b on e.[EmployeId] = b.[CreatedByID]
inner join Projects p on b.ProjectId = p.ProjectId
where e.[EmployeId] = @EmployeeID
group by P.projectName
end
我有几张表,我开始在 LINQ 中写出来,但我不确定如何正确返回正确的类型或强制转换它。
我的控制器
public JsonResult Getchart()
{
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 = @EmployeId
group p.projectName
select new (p.projectName as Project ,count(b.CreatedByID) as Bug)).Take(50);
return Json(result,JsonRequestBehavior.AllowGet);
}
我将如何将参数传递给查询,希望数据以 json 格式返回。