【发布时间】:2020-07-15 18:09:38
【问题描述】:
我正在尝试使用 EF-Core 进行一些查询,我有以下代码
public List<Visitation> GetAllVisitations()
{
return this.hospital.Visitations
.Where(v => v.DoctorId == this.Doctor.Id)
.Select(v => new Visitation
{
Doctor = v.Doctor,
Patient = v.Patient,
Date = v.Date,
Comments = v.Comments
})
.ToList();
}
public List<Visitation> GetVisitationByPatient(int id)
{
var patient = this.GetPatientById(id);
return this.hospital.Visitations
.Where(v => v.PatientId == patient.Id)
.Select(v => new Visitation
{
Doctor = v.Doctor,
Patient = v.Patient,
Date = v.Date,
Comments = v.Comments
})
.ToList();
}
很明显,Select 语句在这两种方法中是相同的。但是我知道 EF Core 使用的是 Expression
【问题讨论】:
-
hospital是什么类型?另外,你有没有尝试过?
标签: c# .net entity-framework entity-framework-core