/// <summary> /// 查询车辆三包信息 /// </summary> /// <param>查询输入</param> /// <param>分页请求</param> /// <returns>带分页的三包预警车辆信息</returns> public async Task<Page<GetVehicleWarrantiesOutput>> GetVehicleWarrantiesAsync(GetVehicleWarrantiesInput input, PageRequest pageRequest) { var queryResults = _vehicleWarrantyRepository.GetAll() .Include(v => v.WarningLevel) .Where(v => _vehicleSoldRepository.GetAll().Any(vs => vs.Status == VehicleStatus.实销完成 && v.Vin == vs.Vin)); var totalCount = await queryResults.CountAsync(); var pagedResults = await queryResults.ProjectTo<GetVehicleWarrantiesOutput>(_autoMapper.ConfigurationProvider).PageAndOrderBy(pageRequest).ToListAsync(); return new Page<GetVehicleWarrantiesOutput>(pageRequest, totalCount, pagedResults); }
在这里我们看到了通过一个Include就可以或许查询出关联的实体,为什么可以或许实现,那是因为在VehicleWarranty实体中存在WarrantyWarningLevel实体的外键,而且这里还增加了外键关联的实体,这样才气够正确利用InClude要领,而且这个InClude要领只可以或许以实体作为参数,不能以外键作为参数,到了这里我想提出一个问题,这里最终生成的SQL(SqlServer数据库)是left join 照旧inner join呢?在看完后头的阐明之前需要思考一下。