I’m using EF Core with Postgres. An entity includes these properties, which I store as JSON:
public ICollection<long> Foo { get; }
public IDictionary<long, long> Bar { get; }
This configuration worked for v7:
builder.Property(x => x.Foo).HasColumnType("jsonb");
builder.Property(x => x.Bar).HasColumnType("jsonb");
But after upgrading to v8, that gave errors. So I updated to the recommended approach for v8:
builder.OwnsOne(x => x.Foo, y => y.ToJson());
builder.OwnsOne(x => x.Bar, y => y.ToJson());
Which gave this error:
Unable to create a ‘DbContext’ of type ”. The exception ‘The specified type ‘System.Collections.Generic.ICollection`1[System.Int64]’ must be a non-interface reference type to be used as an entity type.’ was thrown while attempting to create an instance.
If I change ICollection<long>
to Collection<long>
and IDictionary<long, long>
to Dictionary<long, long>
then the problem disappears.
But I don’t want to expose collection types with that much functionality. Can I somehow get the old behaviour? (I guess I could use one of the readonly collections.)
Also, why is there this change in v8?