I am trying to use JsonB column using a POCO class in .NET core application using entity framework core 6. I tried to create a database migration (add-migration "AddWeek") It gave me below exception in console
The 'Week' property "WeekData.Week" could not be mapped to the database type 'JSONB' because the database provider does not support mapping 'Week' properties to 'JSONB' columns. Consider mapping to a different database type or converting the property value to a type supported by the database using a value converter. See https://aka.ms/efcore-docs-value-converters for more information. Alternately, exclude the property from the model using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
Any help will be greatly appreciated!
Entity class
public class WeekData
{
public Week? Week { get; set; }
}
JSON POCO class
public class Week
{
public int[]? WeekDays { get; set; }
}
Entity framework configuration ModelBuilder
public void Configure(EntityTypeBuilder<WeekData> builder)
{
builder.Property(jc => jc.Week)
.HasColumnName("week")
.HasColumnType("JSONB");
}