This question is locked. New answers and comments are not allowed.
Hello,
I am trying to filter the result of a linq query based on given search criteria.
But during the filter by using where conditions query returns null.
The method is below.
If one of the conditions that filters the query runs it results an error. Which part I am doing wrong.
Please help.
Burhan Eyimaya
Thanks
I am trying to filter the result of a linq query based on given search criteria.
But during the filter by using where conditions query returns null.
The method is below.
public List<ExtremeModel.PatientStudy> ReadPatientStudy2(SearchCriteria critera) |
{ |
IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope(); |
var query = (from p in scope.Extent<Patient>() |
join s in scope.Extent<Study>() on p.Id equals s.PatientId |
select new |
{ |
StudyStatus = s.Status, |
PatientName = p.PatientsName, |
NumImages = s.ImagesCount, |
StudyDateTime = s.Studytime, |
StudyDesc = s.StudyDescription, |
PatBirthDate = p.PatientsBirthDate, |
PatSex = p.PatientSex, |
RefPhysician = s.ReferringPhysiciansName, |
StudyIuid = s.StudyInstanceUid, |
PatientId = p.Id, |
StudyId = s.Id |
}); |
// Conditions |
if(critera.PatientId != 0) |
query = query.Where(ps => ps.PatientId == critera.PatientId); |
if(!string.IsNullOrEmpty(critera.PatientName)) |
query = query.Where(ps => ps.PatientName.Contains(critera.PatientName)); |
if (critera.StudyId != 0) |
query = query.Where(ps => ps.StudyId == critera.StudyId); |
if (critera.StudyStatusList != null) |
{ |
ObservableCollection<int> studyStatusList = critera.StudyStatusList; |
int?[] sList = new int?[studyStatusList.Count]; |
for (int x = 0; x < studyStatusList.Count; x++) |
sList[x] = studyStatusList[x]; |
query = query.Where(ps => sList.Contains(ps.StudyStatus)); |
} |
// Get list |
List<ExtremeModel.PatientStudy> list = new List<ExtremeModel.PatientStudy>(); |
foreach (var ps in query) |
{ |
ExtremeModel.PatientStudy patientStudy = new ExtremeModel.PatientStudy(); |
patientStudy.StudyStatus = ps.StudyStatus; |
patientStudy.PatName = ps.PatientName; |
patientStudy.NumInstances = ps.NumImages; |
patientStudy.StudyDatetime = ps.StudyDateTime; |
patientStudy.StudyDesc = ps.StudyDesc; |
patientStudy.StudyDesc = ps.StudyDesc; |
patientStudy.PatBirthdate = ps.PatBirthDate.ToString(); |
patientStudy.PatSex = ps.PatSex.ToString(); |
patientStudy.RefPhysician = ps.RefPhysician; |
patientStudy.StudyIuid = ps.StudyIuid; |
patientStudy.PatientID = ps.PatientId; |
patientStudy.StudyID = ps.StudyId; |
list.Add(patientStudy); |
} |
return list; |
} |
If one of the conditions that filters the query runs it results an error. Which part I am doing wrong.
Please help.
Burhan Eyimaya
Thanks