OData / OData/AspNetCoreOData

OData Wrapper gets lost on projection

Open
#1,052 3 comments 0 reactions 1 assignee View on GitHub

@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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.