public async Task<List<Teachers>> Handle(Query request, CancellationToken cancellationToken)
{
return await _context.teachers
.Include(s => s.Students)
.ToListAsync();
}
如您所见,
Teacher
和 Student
之间存在多对多关系。此代码仅返回StudentId
.
回应
[
{
"id": 1,
"teacher_FName": "Wonder",
"teacher_LName": "Women",
"activeFlag": 1,
"students": [
{
"studentId": 1,
**"Student": null,**
"teacherId": 1,
"active": 0
},
{
"studentId": 9,
**"Student": null,**
"teacherId": 1,
"active": 1
}
]
}
]
为什么
Student
为空?