尚未能具体找到我问题的答案。

我需要得到一个显示的结果:项目名称ONCE,在给定的日期范围内,对该项目进行了timeEntries的所有用户。

而且我还需要获取timeEntrieshoursEntered),这样我才能计算出该项目总共花费了多少小时。

我对此并不陌生,所以希望我能提供足够的信息。

我的代码:

var dateStart = new DateTime (2016,09,01);
var dateEnd   = new DateTime (2016,09,19);

var query = (from timeEntry in TimeEntries
        join task in Tasks on timeEntry.TaskID equals task.TaskID
        join project in Projects on task.ProjectID equals project.ProjectID
        where timeEntry.DateEntity >= dateStart && timeEntry.DateEntity <= dateEnd
        select new {
        User = timeEntry.User.FirstName + " "+timeEntry.User.LastName,
        Project = timeEntry.Task.Project.ProjectName,
        ProjectId = timeEntry.Task.ProjectID,
        HoursEntered = timeEntry.HoursEntered
        }).GroupBy (q => q.Project).Distinct();


我有4张桌子:


项目(ProjectID,ProjectName)
任务(TaskID,ProjectID)
TimeEntries(HoursEntered,DateEntity,TaskID)
用户(名字,姓氏)

最佳答案

var query =
  from timeEntry in TimeEntries
  where timeEntry.DateEntity >= dateStart && timeEntry.DateEntity <= dateEnd
  select new {
    User = timeEntry.User.FirstName + " "+timeEntry.User.LastName,
    Project = timeEntry.Task.Project.ProjectName,
    ProjectId = timeEntry.Task.ProjectID,
    HoursEntered = timeEntry.HoursEntered
  }

var localRows = query.ToList();

var groups = localRows.GroupBy(x => x.Project);

var projects = groups.Select(g => new {
  Project = g.Key,
  Hours = g.Sum(x => x.HoursEntered),
  Users = g.Select(x => x.User).Distinct().ToList()
}).ToList();

10-07 19:42