Skip to content

Cosmos owned types expose separate __jObject shadow propertyΒ #37399

@JoasE

Description

@JoasE

Bug description

A _jObject shadow property is created for owned types, while it should only be for entity/document root -types.
See: #37322 (comment) for more details

Your code

using var context = new Context(
    new DbContextOptionsBuilder()
    .UseCosmos("AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", "Testing")
    .ConfigureWarnings(x => x.Throw(CoreEventId.ConflictingShadowForeignKeysWarning))
    .Options);

await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();

var entity = new Entity
{
    Id = Guid.NewGuid(),
    OwnedType = new OwnedType
    {
        Id = Guid.NewGuid(),
        Name = "Test"
    }
};

context.Add(entity);
await context.SaveChangesAsync();

Console.WriteLine("Added");
Console.WriteLine(context.Entry(entity).Property<JObject>("__jObject").CurrentValue); // not null
Console.WriteLine(context.Entry(entity.OwnedType).Property<JObject>("__jObject").CurrentValue); // null
Console.WriteLine("");

context.ChangeTracker.Clear();

entity = await context.Set<Entity>().Where(x => x.Id == entity.Id).FirstAsync();
Console.WriteLine("Added retrieved");
Console.WriteLine(context.Entry(entity.OwnedType).Property<JObject>("__jObject").CurrentValue); // not null

public class Context : DbContext
{
    public Context(DbContextOptions options) : base(options)
    {
    }

    protected Context()
    {
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Entity>(entity =>
        {
            entity.Property(x => x.Id);
            entity.OwnsOne(x => x.OwnedType);
        });
    }
}

public class Entity
{
    public Guid Id { get; set; }

    public string Name { get; set; }

    public OwnedType OwnedType { get; set; }
}


public class OwnedType
{
    public Guid Id { get; set; }

    public string Name { get; set; }
}

EF Core version

10.0.0

Database provider

Microsoft.EntityFrameworkCore.Cosmos

Target framework

.NET 10

Operating system

Windows 11

IDE

VS 2026

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions