I have Implemented ODATA and Automapper and facing 2 problems.
1 problem:
If I am using the Data Layer Models, It is giving me correct result:
[EnableQuery]
public IQueryable<Student> GetStudentTest()
{
return _studentService.RetrieveStudent();
}
and the expected result is correct where enrollments and Studentaddress is null:
studentId : 1
firstName : "Captain"
firMiddleName : "Cool"
lastName : "Marvel"
enrollmentDate : "2021-12-28T06:52:52.743"
enrollments : null
studentAddresses : null
But When I use the Automapper and DTO:
[EnableQuery]
public IQueryable<StudentsDTO> GetStudent()
{
return _mapper.ProjectTo<StudentsDTO>(_studentService.RetrieveStudent());
}
The result is wrong that is it gives me result with enrollment and results:
[
{
"studentId": 1,
"firstName": "Captain",
"firMiddleName": "Cool",
"lastName": "Marvel",
"enrollmentDate": "2021-12-28T06:52:52.743",
"enrollments": [
{
"enrollmentId": 1,
"courseId": 1,
"studentId": 1,
"grade": 1,
"course": {
"courseId": 1,
"title": "Course1",
"credits": 5,
"enrollments": null
},
"student": null
}
],
"studentAddresses": [
{
"addressId": 1,
"houseNumber": "5/133",
"city": "Lucknow",
"state": "UttarPradesh",
"studentId": 1,
"students": null
}
]
}
]
2 Problem:
Using OData and Automapper with the query like $expand within $expand:
/api/v1/GetEnrollments?$expand=Student($expand=StudentAddresses),Course
The ProjectTo of automapper doesnt able to bind the data to subtypes as mentioned studentAddresses.
The answers and suggestions will be much appreciated. odata automapper