Linq To Nhibernate - Отдельные запросы - PullRequest
0 голосов
/ 27 августа 2009

У меня следующая ситуация:

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

против

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

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

        totalRecordsCount = totalRecords.Count();

Первый запрос работает полностью, но второй запрос выполняет только

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

и игнорирует условно добавленное выражение where.

Кто-нибудь знает, в чем может быть проблема? Вам нужно больше информации?

Спасибо заранее!

1 Ответ

1 голос
/ 27 августа 2009

Вы на самом деле не применяете где. В вашем if используйте это вместо:

totalRecords = totalRecords.Where(entry =>
                               entry.CustomerAccountInfo.CustomerAccountName == CustomerAccountName &&
                               entry.CustomerAccountInfo.CustomerAccountId == CustomerAccountId);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...