This is a migrated thread and some comments may be shown as answers.

Where filter not working..

3 Answers 92 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
FISCAL
Top achievements
Rank 1
FISCAL asked on 15 Jul 2010, 11:50 AM
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

3 Answers, 1 is accepted

Sort by
0
FISCAL
Top achievements
Rank 1
answered on 15 Jul 2010, 11:55 AM
Hi Again,

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

Cheers,
M G


0
FISCAL
Top achievements
Rank 1
answered on 15 Jul 2010, 12:12 PM
Hi,

I found the problem :)

Forgot to assign it

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

Thanks and Cheers,
MG
0
Damyan Bogoev
Telerik team
answered on 15 Jul 2010, 05:04 PM
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
Tags
LINQ (LINQ specific questions)
Asked by
FISCAL
Top achievements
Rank 1
Answers by
FISCAL
Top achievements
Rank 1
Damyan Bogoev
Telerik team
Share this question
or