【发布时间】:2016-10-25 11:35:45
【问题描述】:
您好,我想在我的 MVC5 应用程序的 C# 中编写 sql Group by query。
在上面的图片中,我有我在 sql 中编写的查询分组。我想用 C# 前端编写。
我尝试在前端编写查询。但是我收到了图片中提到的错误。现在我想用 C# 编写 Group By 查询,并希望显示每个员工的计数(输出与第一张图片中提到的相同)。谁能帮我解决这个问题?
我的 ViewModel(仪表板视图模型)
public class DashboardViewmodel
{
public List<CustomerTypeCountModel> CustomerTypesCountModels { get; set; }
public List<View_VisitorsForm> Visits { get; set; }
public CustomerTypeViewModel CustomerTypeViewModels { get; set; }
public int sizingcount { get; set; }
public int Processingcount { get; set; }
//here i declared two properties
public string EmployeeName { get; set; }
public string EmployeeCount { get; set; }
}
我的控制器代码
[HttpGet]
public ActionResult SalesVisit()
{
return View();
}
public ActionResult GetDatesFromSalesVisit(DashboardViewmodel dvm)
{
var fromdate = Convert.ToDateTime(dvm.CustomerTypeViewModels.FromDate);
var todate = Convert.ToDateTime(dvm.CustomerTypeViewModels.ToDate);
List<View_VisitorsForm> empcount = new List<View_VisitorsForm>();
if (DepartmentID == new Guid("47D2C992-1CB6-44AA-91CA-6AA3C338447E") &&
(UserTypeID == new Guid("106D02CC-7DC2-42BF-AC6F-D683ADDC1824") ||
(UserTypeID == new Guid("B3728982-0016-4562-BF73-E9B8B99BD501"))))
{
var empcountresult = db.View_VisitorsForm.GroupBy(G => G.Employee)
.Select(e => new
{
employee = e.Key,
count = e.Count()
}).ToList();
empcount = empcountresult ;//this line i am getting error
}
DashboardViewmodel obj = new DashboardViewmodel();
return View("SalesVisit", obj);
}
【问题讨论】:
-
还有..请提供sql和错误信息,不要冒充图片..
-
ASP.NET MVC 是一个 Web 框架。它与分组数据无关
标签: c# sql-server linq asp.net-mvc-5