OData / OData/AspNetCoreOData

odata.bind and required properties

Open
#317 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

When creating an entity and using the OData clients SetLink to establish a link to another entity, the linked entity only contains its id. Values for required properties are missing, thus making model state invalid

public class TestA
{
     public int Id { get; set; }
     public TestB B { get; set; }
}

public class TestB
{
    public int Id { get; set; }
    [Required]
    public string Value { get; set; }
}
IEnumerable<TestB> bs = context.TestBs.Execute();
TestA a = new();
context.AddToTestAs(a);
context.SetLink(a, nameof(TestA.B), bs.First());
context.SaveChanges();

Posted data:
{"@odata.type":"#Test.TestA","Id":0,"B@odata.bind":"http://localhost:56168/api/TestBs(1)"}
Break
image

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.

Research direction

Start by reproducing the supplied TestA/TestB example with OData client SetLink and SaveChanges, then trace how the linked entity is represented in the posted OData payload. Check how required properties and model state are handled when only an id is available. Done means the reproduction no longer produces the reported invalid model state, with coverage for the SetLink scenario.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.