Search code examples
c#petapoco

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


I get an error

"Object must implement IConvertible."

When I

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

and myObj has a

System.Data.Entity.Spatial.DbGeography

property. How can I correct this?


Solution

  • A PetaPoco maintainer here. The error is because PetaPoco doesn't know about the type and defaults to trying Convert.ChangeType(src, dstType, null);, which is where I believe the error is originating from.

    Please raise an issue over at the repo if you'd like support this type built-in.

    A quick fix would be for you to implement your own converter logic. An example of this can be found in the 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 for more information.