c# - 如何从 npgsql 反序列化 geojson 多边形
问题描述
尝试使用 ef core 3.1 获取实体形式 npgsql 时出现以下异常
System.NotSupportedException: Deserialization of reference types without parameterless constructor is not supported. Type 'GeoJSON.Net.Geometry.Polygon'
我的实体:
public class VoteEntity : IVoteEntity
{
public Guid Id { get; set; }
[Column(TypeName = "jsonb")]
public Polygon Coordinates { get; set; }
}
解决方案
异常的含义是-您的实体中需要一个无参数的构造函数。
因此,您的实体应该是:
public class VoteEntity : IVoteEntity
{
public Guid Id { get; set; }
[Column(TypeName = "jsonb")]
public Polygon Coordinates { get; set; }
//constructor
public VoteEntity ()
{
//you might want to initialise your properties here
}
}