Skip to content

Inconsistent and Erroring Behavior When Using EF OwnsOne/OwnsMany Mapping #1271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rtablada opened this issue May 10, 2023 · 1 comment · Fixed by #1272
Closed

Inconsistent and Erroring Behavior When Using EF OwnsOne/OwnsMany Mapping #1271

rtablada opened this issue May 10, 2023 · 1 comment · Fixed by #1272
Labels

Comments

@rtablada
Copy link
Contributor

DESCRIPTION

When using EF OwnsOne/OwnsMany properties for nested or complex data structures/mappings JADNC 5 returns inconsistent results, nulls, or errors depending on use of include or sparse fieldsets.

  • For regular requests with no sparse fields and no includes, properties mapped with OwnsOne act as expected
  • When includes for other models are requested properties mapped with OwnsOne will return as null or invalid results
  • When using sparse fields on a resource with OwnsOne mappings, a tracking error is thrown.

STEPS TO REPRODUCE

Full reproduction project: https://github.com/rtablada/JsonApiDotnetExamples

EXPECTED BEHAVIOR

Attrs which expose properties from OwnsOne should allow regular Attr behavior and work with include and fields as any other exposed attribute

ACTUAL BEHAVIOR

OwnsOne Attr properties...

  • return expected result with no complex query string
  • return null when include operations are requested from query string
  • error when sparse fields are requested for OwnsOne attribute

VERSIONS USED

  • JsonApiDotNetCore version: 5.1.2
  • ASP.NET Core version: 7.0.0
  • Entity Framework Core version: 7.0.4
  • Database provider: PG for example project ☝🏽 (occurs with MSSQL as well)
@bkoelman
Copy link
Member

Hi @rtablada, thanks for reporting this and providing great repro instructions.

I've verified that #1272 fixes the two cases from your repro, but you may want to do additional testing. Until now, we didn't have any tests for using owned entities. I haven't looked into OwnsMany usage.

One thing to be aware of: Partial updates do not preserve existing values within statistics. For example:

PATCH https://localhost:7175/countries/1 HTTP/1.1

{
  "data": {
    "type": "countries",
    "id": "1",
    "attributes": {
      "statistics": {
        "population": 456
      }
    }
  }
}

would clear the existing value of gdp. Although EF Core can update just the Population column, JSON:API has no concept of merging the individual fields within an attribute. If you're in need of that, JSON columns may better suit your needs. Adding non-MSSQL support is on the roadmap of EF Core 8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants