Using $top in an $expand with PageSize set results in bad SQL
@xuzhg is already working on this.
Since Sep 16, 2021.
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
Suppose the following query:
School?$expand=Students($top=1)
With the following model:
public class School
{
public int Id { get; set; }
public string Name { get; set; }
public List<Student> Students { get; set; }
}
public class Student
{
public int Id { get; set; }
public string Name { get; set; }
public int SchoolId { get; set; }
public School School { get; set; }
}
And on our GET we have PageSize = 50 (or any number).
The generated SQL will contain the following error:
Invalid column name 'SchoolId'.
For a clone-and-run example, see here:
https://github.com/joshcomley/ODataTopError
Or download:
Interestingly if you remove the PageSize and use the following (technically equivalent) query, it works (the generated SQL is quite different):
School?$expand=Students($top=1)&$top=50
Of course this is no true work-around, neither is setting MaxTop, as clients could still request an entire table of data if they simply omit the $top value.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.