views:

43

answers:

1

Hi all,

I've got the following situation:

        var totalRecords = (from entry in invalidAccEntryRepository
                            select entry).Where(entry =>
                               entry.CustomerAccountInfo.CustomerAccountName == CustomerAccountName &&
                               entry.CustomerAccountInfo.CustomerAccountId == CustomerAccountId).Count();

vs.

        var totalRecords = (from entry in invalidAccEntryRepository
                            select entry);

        if (CustomerAccountInfoFilterActive)
        {
            totalRecords.Where(entry =>
                               entry.CustomerAccountInfo.CustomerAccountName == CustomerAccountName &&
                               entry.CustomerAccountInfo.CustomerAccountId == CustomerAccountId);
        }

        totalRecordsCount = totalRecords.Count();

The first query works completely but the second query only executes the only

var totalRecords = (from entry in invalidAccEntryRepository
                            select entry);

and ignores the conditionally added where expression.

Anyone know what the problem could be? Do you need more info?

Thx in advance!

+1  A: 

You aren't actually applying the where. In your if, use this instead:

totalRecords = totalRecords.Where(entry =>
                               entry.CustomerAccountInfo.CustomerAccountName == CustomerAccountName &&
                               entry.CustomerAccountInfo.CustomerAccountId == CustomerAccountId);
David M
Thanks alot man!
Chris
No problem Chris. :)
David M