MikaelEliasson / EntityFramework.Utilities

Provides extensions for EntityFramework that doesn't exist out of the box like delete and update by query and bulk inserts
443 stars 176 forks source link

support: DbGeography #93

Open lastlink opened 8 years ago

lastlink commented 8 years ago

Bulk insert of lat/long as a 'DbGeography' type throws an error. Is this just not supported?

smithkl42 commented 8 years ago

If you change the EFDataReader.GetValue() method to this, it works, at least in SQL Server (though it breaks the provider architecture - the translation from DbGeo** to SqlGeo** should happen somewhere else):

    public override object GetValue(int ordinal)
    {
        object value = Accessors[ordinal](Enumerator.Current);

        var dbgeo = value as DbGeography;
        if (dbgeo != null)
        {
            var chars = new SqlChars(dbgeo.WellKnownValue.WellKnownText);
            return SqlGeography.STGeomFromText(chars, dbgeo.CoordinateSystemId);
        }

        var dbgeom = value as DbGeometry;
        if (dbgeom != null)
        {
            var chars = new SqlChars(dbgeom.WellKnownValue.WellKnownText);
            return SqlGeometry.STGeomFromText(chars, dbgeom.CoordinateSystemId);
        }

        return value;
    }
smithkl42 commented 8 years ago

@MikaelEliasson - BTW, happy to throw together a patch for the current active version. I took a look at the V2 you're working on, and it looks like it might be a while before a patch landed there would be helpful.