OData / OData/AspNetCoreOData

Post to Contained Entity Collection fails

Open
#726 16 comments 0 reactions 1 assignee View on GitHub

@ElizabethOkerio is already working on this.

Since Oct 25, 2022.

bug
Dominant language
C#
Stars
505
Forks
186
PR merge metrics
No merged PRs in 30d

Description

Assemblies affected
Microsoft.AspNetCore.OData 8.0.11

Describe the bug
https://github.com/lboss75/issue24867.git

I have simple model with contained entity collection:
public class Project
{
..
public virtual IList Modules { get; set; }
}
...
(https://github.com/lboss75/issue24867/blob/main/WebApi/Model/ODataModel.cs)
builder.EntityType().HasMany(x => x.Modules).Contained();

And controller method to post new items into contained collection (https://github.com/lboss75/issue24867/blob/main/WebApi/Controllers/ProjectsController.cs):
public async Task PostToModules([FromODataUri] int key, [FromBody] Module value)

But when I try to call this method I got error:
'The entity type 'WebApi.Module' is not compatible with the base type 'WebApi.Project' of the provided entity set 'Projects'. When an entity type is specified for an OData resource set or resource reader, it has to be the same or a subtype of the base type of the specified entity set.'

I was able to get OData to switch context and accept my parameter only if I write:
builder.EntityType().CollectionProperty(x => x.Modules);
But in this case the type 'WebApi.Module' forced be complex type.

Reproduce steps
Run test in
https://github.com/lboss75/issue24867.git

Data Model
https://github.com/lboss75/issue24867/blob/main/WebApi/Model/Project.cs

public class Project
{

..
public virtual IList Modules { get; set; }
}
...
builder.EntityType().HasMany(x => x.Modules).Contained();

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.