where condition error

4 posts, 0 answers
  1. Burhan Eyimaya
    Burhan Eyimaya avatar
    6 posts
    Member since:
    Jan 2010

    Posted 05 Mar 2010 Link to this post

    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.

    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
  2. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 15 Mar 2010 Link to this post

    Hello Burhan Eyimaya,

    The reason for your issues is that you are appending the where clauses after the select clause in your query. That kind of queries are not correctly processed with the current Linq implementation of Telerik OpenAccess ORM. As a workaround you could do some re-factoring on your method so that you apply the where clauses before making the join and select.

    Here is an example of the possible implementation:
    var patientQuery = scope.Extent<Patient>();
    var studyQuery = scope.Extent<Study>();
     
     
     
          if(critera.PatientId != 0) 
            patientQuery = query.Where(ps => ps.PatientId == critera.PatientId); 
     
        if(!string.IsNullOrEmpty(critera.PatientName)) 
            patientQuery = query.Where(ps => ps.PatientName.Contains(critera.PatientName)); 
     
        if (critera.StudyId != 0) 
            studyQuery = 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]; 
     
            studyQuery = query.Where(ps => sList.Contains(ps.StudyStatus)); 
        }
     
          var queryFinal = (from p in patientQuery
                   join s in sstudyQuery 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 
                     });



    All the best,
    Zoran
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
  4. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 28 Mar 2010 Link to this post

    Are there plans to add that functionality?
  5. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 30 Mar 2010 Link to this post

    Hi Steve,

     Yes, at the moment we are doing some refactoring of the Linq engine in OpenAccess which will allow to write such and other more complex queries for the future.

    Best wishes,
    Zoran
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top