多对多 EF 不返回所有数据

问题描述 投票:0回答:0
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
为空?

entity-framework entity-framework-core
© www.soinside.com 2019 - 2024. All rights reserved.