Linq To Nhibernate - 分离的查询

时间:2009-08-27 13:20:10

标签: linq nhibernate

我遇到以下情况:

        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();

第一个查询完全有效,但第二个查询只执行唯一的

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

并忽略有条件地添加where表达式。

任何人都知道问题可能是什么?你需要更多信息吗?

提前谢谢!

1 个答案:

答案 0 :(得分:1)

你实际上并没有申请。在if中,请改用:

totalRecords = totalRecords.Where(entry =>
                               entry.CustomerAccountInfo.CustomerAccountName == CustomerAccountName &&
                               entry.CustomerAccountInfo.CustomerAccountId == CustomerAccountId);