查找不同表的Startdate和Enddate之间的小时数

时间:2017-12-01 07:06:16

标签: c# sql linq

TimeSheetData timesheetdata = new TimeSheetData();
TimeSheet timeSheet = new TimeSheet();
TimeSheetData timesheetdata = new TimeSheetData();
                        timeSheet.StartDate = thisWeekStart;
                        timeSheet.EndDate = thisWeekEnd;
                        timesheetdata.Date = dt;

                        string HourData = item.Value;
                        string TaskID = item.ID.Split(':')[0];
                        timesheetdata.TaskID = Guid.Parse(TaskID);
                        timesheetdata.TimeSheet = timeSheet;
                        timesheetdata.Hours = Convert.ToDouble(HourData);
                        db.TimesheetData.Add(timesheetdata);
                        db.SaveChanges();                  



var TMS = db.TimeSheets.Where(t => t.StartDate == thisWeekStart 
                                   && t.EndDate == thisWeekEnd).ToList();

我的表是:

  • Timesheets(Guid,Startdate,Enddate)
  • TimeSheetDatas(Guid,小时,日期,任务GUID,时间表指南)

我想在TimesheetDatasStartDateEndDate)之间找到小时(Timesheets)。

 Hours find = var TMS

1 个答案:

答案 0 :(得分:0)

你没有提供一些细节,但是你想要这样的东西;

var query = from ts in db.TimeSheets
join tsd in db.TimesheetDatas on ts.Guid equals tsd.TimesheetGuid
where ts.StartDate > thisWeekStart && ts.StartDate < thisWeekEnd
select tsd.hour