Where filter not working..

4 posts, 0 answers
  1. FISCAL
    FISCAL avatar
    91 posts
    Member since:
    May 2010

    Posted 15 Jul 2010 Link to this post

    Hi,

    I have got a problem with the following dynamic query. The idea is to filter the record based on search parameters provided by the user. Following code should list only audits that matches the where criteria but it is returning all the records. Where filter is completely ignored.

    Could you please kindly let me know what is the problem here?

        if (m_dataContext.Transaction.IsActive == false) m_dataContext.Transaction.Begin();
                IQueryable<AdmAudit> audits = m_dataContext.Extent<AdmAudit>();

                if (dateTo.HasValue)
                {
                    //Convert.ToDateTime is not supported in where clause to it needs to be converted before passing it
                    //OpenAccess implementation lacking
                    dateTo = Convert.ToDateTime(dateTo).Date;
                    audits.Where(audit=> audit.AdmAuditRecordEntered <= dateTo);
                }
                if (dateFrom.HasValue)
                {
                    dateFrom = Convert.ToDateTime(dateFrom).Date;
                    audits.Where(audit => audit.AdmAuditRecordEntered >= dateFrom);
                }
                if (auditSection != "")
                {
                    audits.Where(audit => audit.AdmAuditSection.Contains(Convert.ToString(auditSection)));
                }
                if (auditCategory != "")
                {
                    audits.Where(audit => audit.AdmAuditCategory.Contains(Convert.ToString(auditCategory)));
                }
                List<AdmAudit> finalAudits = (from audit in audits
                                              orderby audit.AdmAuditRecordEntered descending
                                              select audit).ToList();
                return finalAudits;


    Many thanks.

    M G
  2. FISCAL
    FISCAL avatar
    91 posts
    Member since:
    May 2010

    Posted 15 Jul 2010 Link to this post

    Hi Again,

    somehow the code-snippet is not rendered properly so I am attaching it as a screen shot.

    Cheers,
    M G


  3. DevCraft banner
  4. FISCAL
    FISCAL avatar
    91 posts
    Member since:
    May 2010

    Posted 15 Jul 2010 Link to this post

    Hi,

    I found the problem :)

    Forgot to assign it

    audits = audits.Where(audit => audit.AdmAuditSection == auditSection);

    Thanks and Cheers,
    MG
  5. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 15 Jul 2010 Link to this post

    Hello M G,

    We are glad to see that you have managed to solve the problem.

    Greetings,
    Damyan Bogoev
    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