Support complex properties on owned types in JSON-mapped owned collections

Aperta
#39,692 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
52/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
csharp

Direzione di ricerca

Start by reading the discussion on PR #39522, which this issue says must merge first, then trace EF Core's model validation for complex properties mapped inside JSON owned collections. Check the tests for JSON-mapped owned collections and nested owned types. Done means complex properties work for the described nesting patterns and the model validation error no longer blocks them.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area-complex-types area-owned-entities

Follow up to #39522. Filing this issue now to include the id as a comment, not relevant until that PR is merged.

public class Order
{
    public int Id { get; set; }
    public List<OrderLine> Lines { get; set; } = [];
}

public class OrderLine
{
    public string Sku { get; set; }
    public Money Price { get; set; }
}

public class Money
{
    public decimal Amount { get; set; }
    public string Currency { get; set; }
}
modelBuilder.Entity<Order>().OwnsMany(
    o => o.Lines, b =>
    {
        b.ToJson();
        b.ComplexProperty(l => l.Price);
    });

Expected: Price is stored in each element of the Lines JSON array, as it is for OwnsOne(...).ToJson().

Actual: model validation throws:

Complex property 'OrderLine.Price' cannot be declared on 'OrderLine', which is mapped to JSON as part of an owned collection. Complex properties on owned types in JSON collections aren't supported; map the collection with 'ComplexCollection(...).ToJson()' instead.

The same applies to any owned type below a JSON owned collection: an OwnsOne nested in OwnsMany(...).ToJson(), and an OwnsMany nested in OwnsOne(...).ToJson().

Lingua principale
C#
Stelle
14.8k
Fork
3.5k
Merge medio
3g 7h
PR unite (30g)
182

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di dotnet/efcore

Tutte le issue di dotnet/efcore

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.