public List <HardwareDto> GetHardwareDtos() { List <HardwareDto> hardwareDtos = new List <HardwareDto>(); var hardwareDomains = _hardwareRepository.GetAllEntities(); foreach (var hardwareDomain in hardwareDomains) { HardwareDto hardwareDto = new HardwareDto(); hardwareDto.ID = hardwareDomain.ID; hardwareDto.Name = hardwareDomain.Name; hardwareDto.Number = hardwareDomain.Number; hardwareDto.CreateTime = hardwareDomain.CreateTime; hardwareDto.CreateUser = hardwareDomain.CreateUser; //转换工程id为工程名 var projects = from r in _dataContext.Set <Project>() where r.ID == hardwareDomain.ProjectID select r; foreach (var project in projects) { hardwareDto.Project = project.Name; } hardwareDtos.Add(hardwareDto); } return(hardwareDtos); }