선택적 날짜 필드에서 Linq to SQL 쿼리를 필터링하려고하는데 문제가 있습니다. 메서드는 다음과 같습니다.Linq to SQL 날짜 변환 오류
public List<ReferralTrackerModel> GetDoctorDailySchedule(int DBID, int DoctorCode, string apptDateFrom, string apptDateTo)
{
using (var dbIMEC = getISSDataContext(DBID))
{
var eResults = from c in dbIMEC.tblCases
join s in dbIMEC.tblServices on c.ServiceCode equals s.ServiceCode
join e in dbIMEC.tblExaminees on c.ChartNbr equals e.ChartNbr
join p in dbIMEC.tblPublishOnWebs on c.CaseNbr equals p.TableKey
join ct in dbIMEC.tblCaseTypes on c.CaseType equals ct.Code
join l in dbIMEC.tblLocations on c.DoctorLocation equals l.LocationCode.ToString()
where p.UserCode == DoctorCode
where p.TableType == "tblCase"
where p.PublishOnWeb
where p.TableKey == c.CaseNbr
where p.UserType == "DR"
//where c.ApptDate >= DateTime.Parse(apptDateFrom)
//where c.ApptDate <= DateTime.Parse(apptDateFrom).Date.AddHours(23).AddMinutes(59).AddSeconds(59)
select new ReferralTrackerModel()
{
CaseNbr = c.CaseNbr,
ClaimNbr = c.ClaimNbr.Trim(),
ExamLocationName = l.Location.Trim(),
ExamineeName = e.LastName.Trim() + ", " + e.FirstName.Trim(),
CaseType = ct.Description.Trim(),
ServiceDesc = s.Description.Trim(),
ApptDateTime = c.ApptTime.ToString().Trim(),
ApptDateTimeDate = DateTime.Parse(c.ApptTime.ToString())
};
if (apptDateTo.Length > 0)
{
var dateTo = DateTime.Parse(apptDateTo);
eResults = eResults.Where(r => r.ApptDateTimeDate <= dateTo);
}
var lst = eResults.ToList();
return lst;
}
}
The date calculation in the main part of the query is working as expected but the portion after the if statement is not. I am getting the following error back from the API controller:
"message": "메서드 'System.DateTime Parse (System.String)'에 SQL 로의 변환이 지원되지 않습니다."
제 의도는 선택적 apptDateTo 필드가있을 때 결과를 필터링하는 것입니다.
이전에 시도했지만 여전히 동일한 오류가 발생합니다. 나는 당신의 코드를 시도했지만 여전히 오류가 발생합니다. 대답 해줘서 고마워. – CrystalLake62
@ CrystalLake62 : 방금 답변을 업데이트했습니다. LINQ 코드 전체에서'DateTime.Parse()'를 여러 번 사용 한 것처럼 보입니다. 동일한 솔루션이 적용되므로 어디서든 사용해야합니다. – David
이상한 점은 쿼리의 윗부분이 datetime 변환을 사용해도 원하는대로 작동한다는 것입니다. 여전히 조건부에 문제가 있습니다. – CrystalLake62