3

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?

Paul Stanley
  • 1,999
  • 1
  • 22
  • 60

1 Answers1

2

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.

Plebsori
  • 1,075
  • 9
  • 23
  • 1
    I didn't have the need to query the geography type in SqlServer so I converted it to nVarChar max. Converted within c# but it would be useful for Peta Poco to be able to do this. EF6 does but I don't like EF6. Thanks. – Paul Stanley Jan 12 '16 at 09:51
  • I love PetaPoco too. Make sure you check out the newer releases. I've added a few nice features and there's lots of bug fixes too ;) – Plebsori Jan 12 '16 at 20:57