如何获取外键项中的计数

本文关键字:何获取 获取 | 更新日期: 2023-09-27 18:31:24

我需要获取所有bank BankBranches cityId = filter.CityId > 0

法典:

 banks = from bank in banks
            where bank.BankBranches.Where(y => y.CityId == filter.CityId).Count() > 0
            select bank;
    var list = banks.ToList();

错误:

不允许从"Model.Entities.BankBranch"访问成员"Int32 CityId" 'System.Linq.IQueryable 'a [Model.Entities.BankBranch].

如何获取外键项中的计数

 banks = from bank in banks.Include(p=>p.BankBranches)
            where bank.BankBranches.Where(y => y.CityId == filter.CityId).Count() > 0
            select bank;
    var list = banks.ToList();
banks = from bank in banks
        join bankBranche in m_banksRepository.BankBranches on bank.Id equals bankBranche.BankId
        where bankBranche.CityId == filter.CityId
        select bank;