c# - 执行 linq 查询时,它会抛出转换错误 system.int32
问题描述
var Appointment = (from app in _context.Appointments
join pt in _context.Patients on app.PatientID equals pt.ID into
patients
from pt in patients.DefaultIfEmpty()
join doc in _context.Doctors on app.DoctorID equals doc.ID into
doctors
from doc in doctors.DefaultIfEmpty()
//join offloc in _context.OfficeLocations on app.DoctorID
equals offloc.DoctorID into officlocation
//from offloc in officlocation.DefaultIfEmpty()
join docavail in _context.DoctorsAvailabilities on
app.AvailabilityID equals docavail.ID into availability
from docavail in availability.DefaultIfEmpty()
where ((app.CreatedByReferral == ReferralSpecialistID ||
app.CompanyID == CompanyID || app.UserGroupID == CompanyID) &&
app.OtherPatientID == null && pt.Status == StatusConstant.Active
&& app.Status != AppointmentRescheduledID &&
app.IsCloseAppointment != true)
select new AppointmentDataTableResult
{
appointmentID = app.ID,
PatientID = pt.ID,
patientname = (pt.NamePrefix ?? "") + " " + pt.FirstName + " " + pt.LastName + " " + (pt.NameSuffix ?? ""),
ParentPatientID = 0,
dateofbirth = pt.DateOfBirth,
patientType = _context.CategoryDetails.Where(x => x.ItemID == app.PatientTypeID).Select(x => x.MasterData).FirstOrDefault(),
phone = pt.Phone,
Date = docavail.Date,
Time = docavail.Time,
statustext = _context.CategoryDetails.Where(x => x.ItemID == app.Status).Select(x => x.MasterData).FirstOrDefault(),
doctorname = (doc.NamePrefix ?? "") + " " + doc.FirstName + " " + doc.LastName + " " + (doc.NameSuffix ?? ""),
DoctorID = doc.ID,
checkin = app.CheckIn,
checkout = app.CheckOut,
checkintime = app.CheckInTime,
checkouttime = app.CheckOutTime,
withoutslot = app.WithoutSlot,
locatioid = app.LocationID ?? 0,
AppointmentSource = app.AppointmentSource ?? 0,
Status = app.Status ?? 0,
IsPastAppointment = app.IsPastAppointment,
casestatusID = app.CaseStatusID ?? 0,
caseTypeID = app.CaseTypeID ?? 0,
ReferralAttorneyID = app.ReferralAttorneyID ?? 0,
ReferralProviderID = app.ReferralProviderID ?? 0,
patientTypeID = app.PatientTypeID ?? 0,
InsuranceID = app.InsuranceID ?? 0,
PendingAppointmentDate = app.PreferredAppointmentDateTime,
// AppointmentDate = docavail.Date.Value.Month + "/" + docavail.Date.Value.Day + "/" + docavail.Date.Value.Year + " " + docavail.Time.Value.Hours + ":" + docavail.Time.Value.Minutes,
ReportCount = _context.DoctorReportStatus.Where(x => x.StatusID == StatusConstant.Active && x.AppointmentID == app.ID).Count(),
RerecordUploadedYN = app.RerecordUploadedYN,
IsAppointmentPending = app.IsAppointmentPending,
IsPendingBillingRecoardYN = app.IsPendingBillingRecoardYN,
strDate = docavail.Date.Value.Month + "/" + docavail.Date.Value.Day + "/" + docavail.Date.Value.Year,
DateChekin = default(DateTime),
totaldays = 0
});
解决方案
i also face same problem many time this problem occurs when you put Tolist method because before putting the Tolist() method the output generated by the query is of type
IQuerable
but this not the solution of your problem
the problem is that May be 1 you are assigning a Nullable integer type variable to non nullable integer type value or 2 comparing the Nullable integer value to Non Nullable value in Join or vice Versa
chances of second case is greater because when assigning ,c# compiler gives error check your types of compared variable and let me give some follow ups.
推荐阅读
- json - 无法让 json4s 数据提取工作
- java - 我应该在这个 Kotlin 代码中做些什么来打印 1,2,3 ..5 这样的系列数字
- python - Matplot lib:条形图未正确分组
- r - 将 R 内的 GIS 区域联合起来(例如,将县划分为基于核心的统计区域)
- r - 用于将列转换为数字的 for 循环
- wordpress - NextGEN Gallery - 固定链接问题 - urlencode 希伯来语
- unity3d - OnEnable() 方法有替代品吗?
- docker - 在卷默认值中插入 PWD
- python - 从列表中删除多个具有相同小时和分钟的词典?
- java - 伴随对象 Kotlin JNI 中的 UnsatisfiedLinkError