Entity Framework Pomelo MySql JSON columns Error

57 Views Asked by At

Hope someone can assist.

Im attempting to get the JSON columns feature introduced in Entity Framework 7 working on my side. I have an API running the current latest version of Entity Framework Core (version 8.0.1) and Pomelo.EnitiyFramework.MySql (version 7.0.0) but Im getting the following error:

System.InvalidOperationException: The property or navigation 'PicturesJson' cannot be added to the 'Property' type because a property or navigation with the same name already exists on the 'Property' type.

For testing purposes I have 2 simple classes, a Property which will become an entry in the DB table, and a Picture stored as JSON in one of the fields within the same table record:

public class Property
{
    public long Id { get; set; }
    public virtual Picture? PicturesJson { get; set; }
}

and

public class Picture
{
    public string? Name { get; set; }
    public long? Size { get; set; }
}

In my DBContext the models are provided as:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<Property>().Property(p => p.PicturesJson).HasColumnType("json");
    modelBuilder.Entity<Property>().OwnsOne(x => x.PicturesJson, builder => builder.ToJson());
}

I have tried using the latest prerelease of Pomelo.EnityFramework.MySql (Beta 8.0.2) as well but am still getting the same error. According to their documentation the JSON columns feature was included in version 7.

Strange enough when testing it using an SQL Server data store (Microsoft.EntityFrameworkCore.SqlServer 8.0.1) everything works without any issues.

Either the Pomelo library does not fully support JSON columns yet or I am missing something.

Thanks!

0

There are 0 best solutions below