Richard Watts Richard Watts - 10 months ago 67
C# Question

entity framework 6 Dbgeometry.WellKnownValue.WellKnownBinary not being populated

I am using entity framework 6 for crud operations including a DbGeometry property. The property holds a polygon created from WellKnownText.

DbGeometry.PolygonFromText("POLYGON((1.00 1.00, 1.00 80.00, 80.00 80.00, 80.00 1.00, 1.00 1.00))", 27700);

When saving the entity binary data is stored in the spatial database. However when retrieving WellknownValue is being populated with the WellKnownText, however the Dbgeometry.WellKnownValue.WellKnownBinary property is null

(Would post image here but not enough reputation points :( )

Surely this should of been populated from the binary in the database. I have tried setting the field by the AsBinary() method with no success.


Thanks John but unfortunately this is not working either. I have tried:

Property.WellKnownValue.WellKnownBinary = Property.AsBinary();

which still leaves Property.WellKnownValue.WellKnownBinary as null using the QuickWatch window

Also I have tried

byte[] byteVariable = Property.AsBinary();

This does create a 93 byte long byte array I have pasted below, however this seems very empty for what it should contain.


If I then try to assign that byte array to the WellKnownBinary:

Property.WellKnownValue.WellKnownBinary = byteVariable

Property.WellKnownValue.WellKnownBinary is still shown as null using the QuickWatch window

I am seriously running out of ideas :(

Answer Source

I'm not entirely sure why the DbGeometry.WellKnownValue.WellKnownBinary is NULL but it shouldn't matter, the data is stored in SQL in binary format.

You're actually almost there, except DbGeometry.AsBinary() is a getter, not a setter.

So if you do actually need it's value, simply use DbGeometry.AsBinary() to retrieve the value (as a Byte Array).