Skip to content
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

Is it possible to map nested properties? #30692

Closed
danielniccoli opened this issue Apr 14, 2023 · 1 comment
Closed

Is it possible to map nested properties? #30692

danielniccoli opened this issue Apr 14, 2023 · 1 comment
Labels
closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. customer-reported

Comments

@danielniccoli
Copy link

danielniccoli commented Apr 14, 2023

Ask a question

Is it possible to map nested properties?

I have a Cosmos DB item that looks like this:

{
    "id": "955175a3-4d9b-495d-884f-a0b7a632ee88",
    "blueprint": {
        "description": "Decodes a pulse signal at base.\n\nGenerate a pulse signal at outpost by adding a leading and trailing edge detector to an SR latch, and outputting 3 signals at the same time: like [Stone][1][Green]\n\nThen decode it at base using this circuit. Turns light on at green, turns it off on red.",
        "icons": [],
        "entities": [],
        "item": "blueprint",
        "label": "Decode at base",
        "version": 281479276658688
    },
    "_rid": "EVAHAJ1MVP8DAAAAAAAAAA==",
    "_self": "dbs/EVAHAA==/colls/EVAHAJ1MVP8=/docs/EVAHAJ1MVP8DAAAAAAAAAA==/",
    "_etag": "\"5a00217a-0000-0d00-0000-64395f0e0000\"",
    "_attachments": "attachments/",
    "_ts": 1681481486
}

My model at the moment is this:

blueprint.cs

namespace FactorioStudio.Data;

public class Blueprint
{
    public Guid Id { get; set; }
    public string Label? { get; set; }
    public string Description? { get; set; }
}

FactorioStudioContext.cs

using Microsoft.EntityFrameworkCore;

namespace FactorioStudio.Data;

public class FactorioStudioContext : DbContext
{

    public FactorioStudioContext(DbContextOptions<FactorioStudioContext> options) : base(options)    {    }
    public DbSet<Blueprint> Blueprints { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Blueprint>().Property(e => e.Id).ToJsonProperty("id");
        modelBuilder.Entity<Blueprint>()
            .ToContainer(nameof(Blueprints))
            .HasPartitionKey(o => o.Id)
            .HasNoDiscriminator()
            .UseETagConcurrency();

        base.OnModelCreating(modelBuilder);
    }
}

Theoretically, it should be possible, no? I can query the database with this query and it returns the result as expected.

SELECT c.blueprint.label, c.blueprint.description FROM c 
[
    {},
    {},
    {
        "label": "Decode at base",
        "description": "Decodes a pulse signal at base.\n\nGenerate a pulse signal at outpost by adding a leading and trailing edge detector to an SR latch, and outputting 3 signals at the same time: like [Stone][1][Green]\n\nThen decode it at base using this circuit. Turns light on at green, turns it off on red."
    }
]

So I'm hoping there is something along the lines of

modelBuilder.Entity<Blueprint>().Property(e => e.Label).ToJsonProperty("/blueprint/label");

that maps property Label to "/blueprint/label"?

Include provider and version information

EF Core version: 7
Database provider: CosmosDB
Target framework: .NET 7.0
Operating system: Windows 11
IDE: Visual Studio 2022

@ajcvickers
Copy link
Member

@danielniccoli We discussed this, and it is not something we are going to implement. We currently expect the shape of the document to match the shape of the mapped entity types. That being said, weakly typed JSON mapping could be used for this, which is being tracked by #28871.

@roji roji closed this as not planned Won't fix, can't repro, duplicate, stale Apr 22, 2023
@roji roji added the closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. label Apr 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. customer-reported
Projects
None yet
Development

No branches or pull requests

3 participants