I followed the documentation on Postgres C# website.
When I run this code I get:
The entity type 'Bar' requires a primary key to be defined.
POCOs:
public class Foo
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public string Name { get; set; }
[Column(TypeName = "jsonb")]
public Bar Bar { get; set; }
}
public class Bar
{
public string Prop1 { get; set; }
public string Prop2 { get; set; }
}
My goal is to avoid using string
as a property type of Bar and let the entity framework handle JSON serialize, deserialize. I don't want the Bar
to be a separate table. I want it to be a JSON column on Foo
.