Peta Poco 和 System.Data.Entity.Spatial.DbGeography

Peta Poco and System.Data.Entity.Spatial.DbGeography

我收到一个错误

"Object must implement IConvertible."

当我

Database db = new Database(this.ConnStr, this.Provider);
var x = db.Fetch<myObj>(sql);//returns the error

而 myObj 有一个

System.Data.Entity.Spatial.DbGeography

属性。我该如何纠正?

这里是 PetaPoco 的维护者。该错误是因为 PetaPoco 不知道类型并默认尝试 Convert.ChangeType(src, dstType, null);,我认为这是错误的来源。

如果你想支持这种类型,请提出问题over at the repobuilt-in。

一个快速的解决方法是实现您自己的转换器逻辑。有关详细信息,请参阅 SQLite integration test code. If you don't want to use the ConventionMapper or you're using an older version of PetaPoco, you can always register a customer mapper for the specific type. See the mapping docs 中的示例。