解决方案一:等号两边都转换格式再比较
System.Data.Entity.DbFunctions.TruncateTime(airHourly.Date)
dateHour = dateHour.Date;
解决方案二: 等号改成区间
DateTime dateHour = DateTime.Now.Date;
DateTime dateHourEnd = DateTime.Now.Date.AddDays(1);
airHourly.Date >=dateHour &&airHourly.Date<dateHourEnd
private JsonResult StreetStationHourlyData(PageModel pageInfo, DateTime dateHour, string[] stations)//, string[] param, string[] stationTypeArray { ResultModel result = new ResultModel(); if (pageInfo.Page <= 0) { pageInfo.Page = 1; } if (pageInfo.Rows <= 0) { pageInfo.Rows = 20; } //int[] stationIntArray = Array.ConvertAll<string, int>(stations, s => int.Parse(s)); dateHour = dateHour.Date; var data = from airHourly in dbq.T_AirStreetDataHourly2 join station in dbq.T_AirStreetStation2 on airHourly.StationID equals station.StationID.ToString() where airHourly.StationID != null && System.Data.Entity.DbFunctions.TruncateTime(airHourly.Date) == dateHour && stations.Contains(station.StationID.ToString()) //&& stationTypeArray.Contains(station.SeatType.ToString()) orderby airHourly.StationID, airHourly.Date.Hour select new { station.StationName, airHourly.StationID, airHourly.Date, airHourly.O3, airHourly.PM10, airHourly.PM25, Hour=airHourly.Date.Hour, station.Hierarchy, station.SeatType, station.PointNature, station.IsStreet }; //排序 if (pageInfo.Order != null && pageInfo.Sort != null) { bool isAsc = pageInfo.Order == "asc"; data = data.OrderBy(new[] { pageInfo.Sort }, new[] { isAsc }); } result.rows = data.Skip((pageInfo.Page - 1) * pageInfo.Rows).Take(pageInfo.Rows).ToList(); result.total = data.Count(); result.success = true; return Json(result, JsonRequestBehavior.AllowGet); }