【发布时间】:2021-08-13 16:17:51
【问题描述】:
我在过去 2 天尝试使用 aspnetboilerplate 创建简单的 INNER JOIN,而我m getting error that I really dont 知道如何处理。
我的观点是,我需要在 ObjectMapper.Map 中添加两个 DTO
我的代码:
StudentDto
[AutoMap(typeof(Student))]
public class Student: EntityDto
{
public string Name { get; set; }
public int Last_Name{ get; set; }
public int City_Id { get; set; }
}
}
CityDto
[AutoMap(typeof(City))]
public class CityDto : EntityDto
{
public string Name{ get; set; }
public string Address{ get; set; }
}
StudentAppService.cs
private readonly IRepository<Student> _studentRepository;
private readonly IRepository<City> _cityRepository;
public StudentAppService(IRepository<Student> _studentRepository, IRepository<City> _cityRepository)
{
_studentRepository = studentRepository ;
_cityRepository = cityRepository ;
}
public List<StudentDto> GetStudentWithCityName()
{
var data = (from s in _studentRepository.GetAll() join c in _cityRepository.GetAll() on s.City_Id equals c.Id select new { name = s.Name }).ToList();
return ObjectMapper.Map<List<StudentDto>>(data);
}
当我构建应用程序并尝试使用 SWAGGER 执行 GET 时,我收到此错误(带有我想要的数据值)
谁能帮我解决这个问题?
【问题讨论】:
-
您从 repo 中选择了一个匿名对象 (
new { ... }),而不是Student,但配置了StudentDto和Student之间的映射
标签: c# asp.net-core aspnetboilerplate