OData Wrapper gets lost on projection
Open
@xuzhg is already working on this.
Since Sep 15, 2023.
bug
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
Assemblies affected
ASP.NET Core OData 8.x (latest)
Describe the bug
When applying own projection/select to the query the odata wrapper get's lost.
Reproduce steps
public ActionResult<IQueryable> Get(ODataQueryOptions<ArticleInfo> odata)
{
var query = DbContext.ArticleInfos.FromSqlRaw("select 'abc' as Id, 'somevalue' as Value union select 'xyz','othervalue'");
var newQuery = odata.ApplyTo(query);
// this line eliminates OData wrapper
var finalQuery = newQuery.Cast<ArticleInfo>().Select(a => new { a.Value });
return Ok(finalQuery);
}
Data Model
public class ArticleInfo
{
[Key]
public string Id { get; set; }
public string Value{ get; set; }
}
EDM (CSDL) Model
<EntityType Name="ArticleInfo">
<Key>
<PropertyRef Name="Id"/>
</Key>
<Property Name="Id" Type="Edm.String" Nullable="false"/>
<Property Name="Value" Type="Edm.String"/>
</EntityType>
Request/Response
GET Request
ArticleInfos?$filter=Id%20eq%20%27abc%27
Response
[{"Value":"somevalue"}]
Expected behavior
Should be this response:
{"@odata.context":"https://localhost:7188/coreservices/odata/$metadata#ArticleInfos(Value)","value":[{"Value":"somevalue"}]}
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.