i've adapted an existing asp.net based rest api and although the query seems to work, the controller is not returning the expanded collection.
The Get is done like this:
[HttpGet("projects/{projectId}/issues", Name = "GetOdataGeminiIssues")]
[Produces("application/json")]
[ProducesResponseType(typeof(IQueryable<GeminiIssue>), Status200OK)]
[ProducesResponseType(Status400BadRequest)]
public async Task<IActionResult> GetGeminiIssues(long projectId, ODataQueryOptions<GeminiIssue> options)
{
var issues = await _geminiRepository
.GetQueryableIssues(projectId)
.GetQueryAsync(_mapper, options, new QuerySettings { ODataSettings = new ODataSettings { HandleNullPropagation = HandleNullPropagationOption.False } });
return Ok(issues);
}
The EDM Model. I had only builder.EntitySet("projects"); before, i've tried to define the relations to see if it works but no success there:
private static IEdmModel GetEdmModel()
{
var builder = new ODataConventionModelBuilder();
var issue = builder.EntityType<GeminiIssue>().Expand(10).Filter().Count().Select().Page();
issue.HasMany<GeminiIssueHistory>(x => x.HistoryItems);
issue.HasMany<GeminiCustomField>(x => x.CustomFields);
builder.EntitySet<GeminiIssue>("projects");
builder.EntitySet<GeminiIssueHistory>(nameof(GeminiIssueHistory));
builder.EntitySet<GeminiCustomField>(nameof(GeminiCustomField));
return builder.GetEdmModel();
}
The models - this are the DTOs that i map to from EF Core.
public class GeminiIssue
{
[Key]
public decimal IssueId { get; set; }
//... more properties
public ICollection<GeminiIssueHistory>? HistoryItems { get; set; }
public ICollection<GeminiCustomField>? CustomFields { get; set; }
}
public class GeminiIssueHistory
{
[Key]
public decimal HistoryId { get; set; }
//... more properties, however no link back to GeminiIssue
}
If the data back is being returned to the controller then the problem should be unrelated to this library. Comparing your controller and OData configuration to our samples might help.
Hi,
i've adapted an existing asp.net based rest api and although the query seems to work, the controller is not returning the expanded collection.
The Get is done like this:
The EDM Model. I had only builder.EntitySet("projects"); before, i've tried to define the relations to see if it works but no success there:
The models - this are the DTOs that i map to from EF Core.
The end points:
My request is straightforward: http://localhost:45179/odata/projects/184/issues?$expand=HistoryItems&$top=1
But I get no expansions:
And the packages:
The strange thing is that if i execute the query, it shows me that the expanded items are there, but they do not reach the client:
Is this a asp.net odata issue?
Thanks, Marco