[英]Difficulty with Linq on inner and left outer joins
I can't see why this fails. 我不明白为什么这失败了。 The error is:
错误是:
Failure: Identifier 'Patient_recid' is not a parameter or variable or field of 'Nova.Data.Returntooffice'.
失败:标识符“ Patient_recid”不是“ Nova.Data.Returntooffice”的参数或变量或字段。 If 'Patient_recid' is a property please add the FieldAlias or Storage attribute to it or declare it as a field's alias.
如果“ Patient_recid”是属性,请向其添加FieldAlias或Storage属性,或将其声明为字段的别名。
Yep...that is correct. 是的...是的。 The tables are set up such that
表格设置为
Returntooffices
references an encountertimes
record (inner join). Returntooffices
引用了一个encountertimes
记录(内部Returntooffices
)。 encountertimes
record references patient
table record (inner join). encountertimes
记录引用patient
表记录(内部联接)。 Returntoooffice
record may or may not have an appointment
record --This is the reason I am trying to use a left outer join. Returntoooffice
记录可能有也可能没有appointment
记录-这就是我尝试使用左外部Returntoooffice
的原因。 The returntooffices
record DOES NOT have a patient_recid
, and this is why I am attempting to join it to a encountertimes
record. returntooffices
记录没有patient_recid
,这就是为什么我试图将其加入一个encountertimes
记录。
How is this done correctly? 如何正确完成?
TIA TIA
var query =
from rto in cxt.Returntooffices
from encounter in cxt.Encountertimes.Where(f => f.Recid == rto.Encounter_recid)
from patient in cxt.Patients.Where(p => p.Recid == encounter.Patient_recid && p.Groupid == groupid)
from appointment in cxt.Appointments.Where(a => a.Recid == rto.Appointment_recid).DefaultIfEmpty()
select new
{
RTO = rto,
APPOINTMENT = appointment
};
var b = query.ToList();
In lieu of a better idea, this seems to compile and work (yea!) 代替一个更好的主意,这似乎可以编译并起作用(是的!)
var q =
from rto in cxt.Returntooffices
join encounter in cxt.Encountertimes on rto.Encounter_recid equals encounter.Recid
join patient in cxt.Patients on encounter.Patient_recid equals patient.Recid
join appointment in cxt.Appointments on rto.Appointment_recid equals appointment.Recid into apt
from a in apt.DefaultIfEmpty()
where patient.Groupid == groupid
select new
{
RTO = rto,
APPOINTMENT = a
}
).ToList();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.