Skip to content

Specifying ToJson().HasColumnType("json") make querying throw an exception #3475

@Mandrakia

Description

@Mandrakia

EntityFramework.Core : 9.0.2,
Npgsql.EntityFrameworkCore : 9.0.3

    public class TestEntity
    {
        public int Id { get; set; }
        public string Title { get; set; }
        public List<Blog> Blogs { get; set; }
    }

    public class Blog
    {
        public string Title { get; set; }
        public string Content { get; set; }
    }

    public class Context : DbContext
   {
    protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<TestEntity>(entity =>
            {
                entity.OwnsMany(a => a.Blogs, b =>
                {
                    b.ToJson().HasColumnType("json");
                });
            });
            base.OnModelCreating(modelBuilder);
        }
 }

Migration : Ok (has proper column type)
Insertion : Ok
Querying : System.InvalidOperationException: No coercion operator is defined between types 'System.Text.Json.JsonElement' and 'System.IO.MemoryStream'

When removing the HasColumnType("json").
Both insertion & querying work despite the column being "json" and not "jsonb"
But migrating will change the column to jsonb.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions