efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Support JSON properties with TPT/TPC inheritance mapping

Open maumar opened this issue 3 years ago • 13 comments

Currently only TPH inheritance is supported.

maumar avatar Jul 13 '22 21:07 maumar

Hi @maumar, @AndriySvyryd and @ajcvickers . Do we have a timeline for this?

mahdishahbazi avatar Nov 26 '22 04:11 mahdishahbazi

@mahdishahbazi this is being considered for the 8.0 release, but it may or may not make it in.

roji avatar Nov 26 '22 08:11 roji

Is there any progress related to this?

niltor avatar Nov 21 '23 02:11 niltor

Is there any progress related to this?

VoronkoVK avatar Jan 04 '24 17:01 VoronkoVK

This issue is currently in the backlog, though we hope to be able to tackle this for 9.0. Please don't post "any progress" messages - that mostly spams the issue, taking up our time in looking at the message and responding to it.

roji avatar Jan 04 '24 17:01 roji

The docs for TPC strategy really need to list all these limitations as a big warning! It's quite painful to find out that feature x, y, and z is not supported when using TPC or hierarchies in general, AFTER designing around it.

I hope these features exist eventually, but for now guiding users away from the feature when they're just gonna cause themselves pain seems prudent.

douglasg14b avatar Feb 12 '24 02:02 douglasg14b

A workaround, or how it has traditionally been done:

public class BaseClassConfiguration : IEntityTypeConfiguration<BaseClass>
{
    public void Configure(EntityTypeBuilder<BaseClass> builder)
    {
        builder.UseTpcMappingStrategy();

        builder
            .Property(b => b.JsonProperty)
            .HasConversion(
                x => JsonSerializer.Serialize(x, JsonSerializerOptions.Default),
                x => JsonSerializer.Deserialize<SomeType>(x, JsonSerializerOptions.Default))
            .IsUnicode();
    }
}

This does mean you can't query and index the JSON values within but at least you can store it.

JasonLandbridge avatar Mar 29 '24 21:03 JasonLandbridge

Every time I turn around there's another limitation I bumped into

onionhammer avatar Jun 10 '24 20:06 onionhammer

any traction on this?

SahilAroraSS avatar Nov 02 '24 20:11 SahilAroraSS

Just faced the issue today. Hoping to see this implemented soon!

RomainHautefeuille avatar Mar 04 '25 07:03 RomainHautefeuille

Our team ran into this limitation with a TPT configuration today as well.

notmods avatar Oct 23 '25 18:10 notmods

I ran into this today in Nov 2025. I didn't see this limitation anywhere when we build infrastructure. Now when I want to use the json column when we need to, it turns out we can't. I'm unable to describe how mad I am.

pgolinski avatar Nov 27 '25 11:11 pgolinski

@pgolinski see this workaround: https://github.com/dotnet/efcore/issues/28443#issuecomment-2027749257

JasonLandbridge avatar Nov 27 '25 12:11 JasonLandbridge