public override object CreateProviderValue(DbGeometryWellKnownValue wellKnownValue) { CheckParameterNotNull("wellKnownValue", wellKnownValue); if (wellKnownValue.WellKnownText != null) { return(InvokeStaticFunction( SqlTypes.SqlGeometryType, "STGeomFromText", SqlTypes.SqlCharsFromString(wellKnownValue.WellKnownText), wellKnownValue.CoordinateSystemId)); } else if (wellKnownValue.WellKnownBinary != null) { return(InvokeStaticFunction( SqlTypes.SqlGeometryType, "STGeomFromWKB", SqlTypes.SqlBytesFromByteArray(wellKnownValue.WellKnownBinary), wellKnownValue.CoordinateSystemId)); } else { throw new ArgumentException("wellKnownValue"); } }
/// <summary> /// Converts DbGeography/DbGeometry values to corresponding Sql Server spatial values. /// </summary> /// <param name="value">value to convert</param> /// <returns>Sql Server spatial value for DbGeometry/DbGeography or <paramref name="value"/>.</returns> internal static object EnsureSqlParameterValue(object value) { if (value != null && value != DBNull.Value && Type.GetTypeCode(value.GetType()) == TypeCode.Object) { // If the parameter is being created based on an actual value (typically for constants found in DML expressions) then a DbGeography/DbGeometry // value must be replaced by an an appropriate Microsoft.SqlServer.Types.SqlGeography/SqlGeometry instance. Since the DbGeography/DbGeometry // value may not have been originally created by this SqlClient provider services implementation, just using the ProviderValue is not sufficient. DbGeography geographyValue = value as DbGeography; if (geographyValue != null) { value = SqlTypes.ConvertToSqlTypesGeography(geographyValue); } else { DbGeometry geometryValue = value as DbGeometry; if (geometryValue != null) { value = SqlTypes.ConvertToSqlTypesGeometry(geometryValue); } } } return(value); }
public override DbGeometry GeometryFromText(string wellKnownText, int coordinateSystemId) { CheckParameterNotNull("wellKnownText", wellKnownText); var providerValue = InvokeStaticFunction( SqlTypes.SqlGeometryType, "STGeomFromText", SqlTypes.SqlCharsFromString(wellKnownText), coordinateSystemId); return(GeometryFromProviderValue(providerValue)); }
public override DbGeometry GeometryFromGml(string geometryMarkup, int coordinateSystemId) { CheckParameterNotNull("geometryMarkup", geometryMarkup); var providerValue = InvokeStaticFunction( SqlTypes.SqlGeometryType, "GeomFromGml", SqlTypes.SqlXmlFromString(geometryMarkup), coordinateSystemId); return(GeometryFromProviderValue(providerValue)); }
public override DbGeometry GeometryFromBinary(byte[] wellKnownBinary, int coordinateSystemId) { CheckParameterNotNull("wellKnownBinary", wellKnownBinary); var providerValue = InvokeStaticFunction( SqlTypes.SqlGeometryType, "STGeomFromWKB", SqlTypes.SqlBytesFromByteArray(wellKnownBinary), coordinateSystemId); return(GeometryFromProviderValue(providerValue)); }