/// <summary> /// Call this method from the constructor of a class derived from <see cref="DbConfiguration" /> to set /// an implementation of <see cref="DbSpatialServices" /> which will be used whenever a spatial provider is /// required. Normally the spatial provider is obtained from the EF provider's <see cref="DbProviderServices" /> /// implementation, but this can be overridden using this method. This also allows stand-alone instances of /// <see cref="DbGeometry" /> and <see cref="DbGeography" /> to be created using the correct provider. /// Note that only one spatial provider can be set in this way; it is not possible to set different spatial providers /// for different EF/ADO.NET providers. /// </summary> /// <remarks> /// This method is provided as a convenient and discoverable way to add configuration to the entity framework. /// Internally it works in the same way as using AddDependencyResolver to add an appropriate resolver for /// <see cref="IDbModelCacheKeyFactory" />. This means that, if desired, the same functionality can be achieved using /// a custom resolver or a resolved backed by an Inversion-of-Control container. /// </remarks> /// <param name="keyFactory"> The key factory. </param> protected internal void SetSpatialProvider(DbSpatialServices spatialProvider) { Check.NotNull(spatialProvider, "spatialProvider"); _internalConfiguration.CheckNotLocked("SetSpatialProvider"); _internalConfiguration.RegisterSingleton(spatialProvider, null); }
public override DbGeography GeographyFromText( string geographyText, int spatialReferenceSystemId) { Check.NotNull <string>(geographyText, nameof(geographyText)); return(DbSpatialServices.CreateGeography((DbSpatialServices)this, (object)new DefaultSpatialServices.ReadOnlySpatialValues(spatialReferenceSystemId, geographyText, (byte[])null, (string)null))); }
public override DbGeometry GeometryFromGml(string geometryMarkup, int spatialReferenceSystemId) { geometryMarkup.CheckNull("geometryMarkup"); ReadOnlySpatialValues backingValue = new ReadOnlySpatialValues(spatialReferenceSystemId, textValue: null, binaryValue: null, gmlValue: geometryMarkup); return(DbSpatialServices.CreateGeometry(this, backingValue)); }
public DbSpatialServices GetSpatialServices(string manifestToken) { try { DbSpatialServices spatialServices = DbGetSpatialServices(manifestToken); if (spatialServices == null) { throw EntityUtil.ProviderIncompatible(Strings.ProviderDidNotReturnSpatialServices); } return(spatialServices); } catch (ProviderIncompatibleException) { throw; } catch (Exception e) { if (EntityUtil.IsCatchableExceptionType(e)) { throw EntityUtil.ProviderIncompatible(System.Data.Entity.Strings.ProviderDidNotReturnSpatialServices, e); } throw; } }
public override DbGeography GeographyFromBinary( byte[] geographyBinary, int spatialReferenceSystemId) { Check.NotNull <byte[]>(geographyBinary, nameof(geographyBinary)); return(DbSpatialServices.CreateGeography((DbSpatialServices)this, (object)new DefaultSpatialServices.ReadOnlySpatialValues(spatialReferenceSystemId, (string)null, geographyBinary, (string)null))); }
public override DbGeometry GeometryFromProviderValue(object providerValue) { providerValue.CheckNull("providerValue"); object normalizedProviderValue = NormalizeProviderValue(providerValue, this.SqlTypes.SqlGeometryType); return(this.SqlTypes.IsSqlGeometryNull(normalizedProviderValue) ? null : DbSpatialServices.CreateGeometry(this, normalizedProviderValue)); }
public override DbGeometry GeometryFromText(string geometryText) { geometryText.CheckNull("geometryText"); ReadOnlySpatialValues backingValue = new ReadOnlySpatialValues(DbGeometry.DefaultCoordinateSystemId, textValue: geometryText, binaryValue: null, gmlValue: null); return(DbSpatialServices.CreateGeometry(this, backingValue)); }
public override DbGeography GeographyFromGml(string geographyMarkup) { geographyMarkup.CheckNull("geographyMarkup"); ReadOnlySpatialValues backingValue = new ReadOnlySpatialValues(DbGeography.DefaultCoordinateSystemId, textValue: null, binaryValue: null, gmlValue: geographyMarkup); return(DbSpatialServices.CreateGeography(this, backingValue)); }
public override DbGeometry GeometryFromBinary(byte[] geometryBinary, int spatialReferenceSystemId) { geometryBinary.CheckNull("geometryBinary"); ReadOnlySpatialValues backingValue = new ReadOnlySpatialValues(spatialReferenceSystemId, textValue: null, binaryValue: geometryBinary, gmlValue: null); return(DbSpatialServices.CreateGeometry(this, backingValue)); }
public override DbGeography GeographyFromText(string geographyText, int spatialReferenceSystemId) { geographyText.CheckNull("geographyText"); ReadOnlySpatialValues backingValue = new ReadOnlySpatialValues(spatialReferenceSystemId, textValue: geographyText, binaryValue: null, gmlValue: null); return(DbSpatialServices.CreateGeography(this, backingValue)); }
public override DbGeography GeographyFromBinary(byte[] geographyBinary) { geographyBinary.CheckNull("geographyBinary"); ReadOnlySpatialValues backingValue = new ReadOnlySpatialValues(DbGeography.DefaultCoordinateSystemId, textValue: null, binaryValue: geographyBinary, gmlValue: null); return(DbSpatialServices.CreateGeography(this, backingValue)); }
public override DbGeometry GeometryFromProviderValue(object providerValue) { return (providerValue == null || ((dynamic)providerValue).IsNull ? null : DbSpatialServices.CreateGeometry(this, providerValue)); }
public override DbGeometry GeometryFromGml( string geometryMarkup, int spatialReferenceSystemId) { Check.NotNull <string>(geometryMarkup, nameof(geometryMarkup)); return(DbSpatialServices.CreateGeometry((DbSpatialServices)this, (object)new DefaultSpatialServices.ReadOnlySpatialValues(spatialReferenceSystemId, (string)null, (byte[])null, geometryMarkup))); }
internal DbGeometry(DbSpatialServices spatialServices, object spatialProviderValue) { DebugCheck.NotNull(spatialServices); DebugCheck.NotNull(spatialProviderValue); _spatialProvider = spatialServices; _providerValue = spatialProviderValue; }
/// <summary> /// Call this method from the constructor of a class derived from <see cref="DbConfiguration" /> to add /// an implementation of <see cref="DbSpatialServices" /> to use for a specific provider. /// </summary> /// <remarks> /// This method is provided as a convenient and discoverable way to add configuration to the Entity Framework. /// Internally it works in the same way as using AddDependencyResolver to add an appropriate resolver for /// <see cref="DbSpatialServices" />. This means that, if desired, the same functionality can be achieved using /// a custom resolver or a resolver backed by an Inversion-of-Control container. /// </remarks> /// <param name="providerInvariantName"> The ADO.NET provider invariant name indicating the type of ADO.NET connection for which this spatial provider will be used. </param> /// <param name="spatialProvider"> The spatial provider. </param> protected internal void AddDbSpatialServices(string providerInvariantName, DbSpatialServices spatialProvider) { Check.NotEmpty(providerInvariantName, "providerInvariantName"); Check.NotNull(spatialProvider, "spatialProvider"); _internalConfiguration.CheckNotLocked("AddDbSpatialServices"); RegisterDbSpatialServices(providerInvariantName, spatialProvider); }
internal DbGeography(DbSpatialServices spatialServices, object spatialProviderValue) { Check.NotNull(spatialServices, "spatialServices"); Check.NotNull(spatialProviderValue, "spatialProviderValue"); _spatialProvider = spatialServices; _providerValue = spatialProviderValue; }
/// <summary> /// Call this method from the constructor of a class derived from <see cref="DbConfiguration" /> to add /// an implementation of <see cref="DbSpatialServices" /> to use for a specific provider and provider /// manifest token. /// </summary> /// <remarks> /// This method is provided as a convenient and discoverable way to add configuration to the Entity Framework. /// Internally it works in the same way as using AddDependencyResolver to add an appropriate resolver for /// <see cref="DbSpatialServices" />. This means that, if desired, the same functionality can be achieved using /// a custom resolver or a resolver backed by an Inversion-of-Control container. /// </remarks> /// <param name="providerInvariantName"> The ADO.NET provider invariant name indicating the type of ADO.NET connection for which this spatial provider will be used. </param> /// <param name="spatialProvider"> The spatial provider. </param> protected internal void AddDbSpatialServices(DbProviderInfo key, DbSpatialServices spatialProvider) { Check.NotNull(key, "key"); Check.NotNull(spatialProvider, "spatialProvider"); _internalConfiguration.CheckNotLocked("AddDbSpatialServices"); _internalConfiguration.RegisterSingleton(spatialProvider, key); }
internal DbGeography(DbSpatialServices spatialServices, object spatialProviderValue) { Debug.Assert(spatialServices != null, "Spatial services are required"); Debug.Assert(spatialProviderValue != null, "Provider value is required"); this.spatialSvcs = spatialServices; this.providerValue = spatialProviderValue; }
/// <summary> /// Call this method from the constructor of a class derived from <see cref="DbConfiguration" /> to add /// an implementation of <see cref="DbSpatialServices" /> to use for a specific provider. /// </summary> /// <remarks> /// The given spatial provider type should have a <see cref="DbProviderNameAttribute" /> applied to it. /// This method is provided as a convenient and discoverable way to add configuration to the Entity Framework. /// Internally it works in the same way as using AddDependencyResolver to add an appropriate resolver for /// <see cref="DbSpatialServices" />. This means that, if desired, the same functionality can be achieved using /// a custom resolver or a resolver backed by an Inversion-of-Control container. /// </remarks> /// <param name="spatialProvider"> The spatial provider. </param> protected internal void AddDbSpatialServices(DbSpatialServices spatialProvider) { Check.NotNull(spatialProvider, "spatialProvider"); _internalConfiguration.CheckNotLocked("AddDbSpatialServices"); foreach (var providerInvariantNameAttribute in DbProviderNameAttribute.GetFromType(spatialProvider.GetType())) { RegisterDbSpatialServices(providerInvariantNameAttribute.Name, spatialProvider); } }
private static object GetSpatialValueFromProviderValue( object spatialValue, PrimitiveType parameterType, EntityConnection connection) { DbSpatialServices spatialServices = DbProviderServices.GetSpatialServices(DbConfiguration.DependencyResolver, connection); if (Helper.IsGeographicType(parameterType)) { return((object)spatialServices.GeographyFromProviderValue(spatialValue)); } return((object)spatialServices.GeometryFromProviderValue(spatialValue)); }
private static DbSpatialServices GetSpatialServices( IDbDependencyResolver resolver, DbProviderInfo key, Func <DbProviderServices> providerServices) { DbSpatialServices orAdd = DbProviderServices._spatialServices.GetOrAdd(key, (Func <DbProviderInfo, DbSpatialServices>)(k => resolver.GetService <DbSpatialServices>((object)k) ?? providerServices().GetSpatialServices(k.ProviderManifestToken) ?? resolver.GetService <DbSpatialServices>())); if (orAdd == null) { throw new ProviderIncompatibleException(Strings.ProviderDidNotReturnSpatialServices); } return(orAdd); }
private void RegisterDbSpatialServices(string providerInvariantName, DbSpatialServices spatialProvider) { DebugCheck.NotEmpty(providerInvariantName); DebugCheck.NotNull(spatialProvider); _internalConfiguration.RegisterSingleton( spatialProvider, k => { var asSpatialKey = k as DbProviderInfo; return(asSpatialKey != null && asSpatialKey.ProviderInvariantName == providerInvariantName); }); }
public virtual DbSpatialServices LoadDefaultServices() { DbSpatialServices service1 = this._resolver.GetService <DbSpatialServices>(); if (service1 != null) { return(service1); } DbSpatialServices service2 = this._resolver.GetService <DbSpatialServices>((object)new DbProviderInfo("System.Data.SqlClient", "2012")); if (service2 != null && service2.NativeTypesAvailable) { return(service2); } return((DbSpatialServices)DefaultSpatialServices.Instance); }
private static object GetSpatialValueFromProviderValue(object spatialValue, PrimitiveType parameterType, EntityConnection connection) { DbProviderServices providerServices = DbProviderServices.GetProviderServices(connection.StoreConnection); StoreItemCollection storeItemCollection = (StoreItemCollection)connection.GetMetadataWorkspace().GetItemCollection(DataSpace.SSpace); DbSpatialServices spatialServices = providerServices.GetSpatialServices(storeItemCollection.StoreProviderManifestToken); if (Helper.IsGeographicType(parameterType)) { return(spatialServices.GeographyFromProviderValue(spatialValue)); } else { Debug.Assert(Helper.IsGeometricType(parameterType)); return(spatialServices.GeometryFromProviderValue(spatialValue)); } }
internal SqlSpatialDataReader( DbSpatialServices spatialServices, SqlDataReaderWrapper underlyingReader) { this._spatialServices = spatialServices; this._reader = underlyingReader; int fieldCount = this._reader.FieldCount; this._geographyColumns = new bool[fieldCount]; this._geometryColumns = new bool[fieldCount]; for (int i = 0; i < this._reader.FieldCount; ++i) { string dataTypeName = this._reader.GetDataTypeName(i); if (dataTypeName.EndsWith("sys.geography", StringComparison.Ordinal)) { this._geographyColumns[i] = true; } else if (dataTypeName.EndsWith("sys.geometry", StringComparison.Ordinal)) { this._geometryColumns[i] = true; } } }
internal SqlSpatialDataReader(DbSpatialServices spatialServices, SqlDataReaderWrapper underlyingReader) { _spatialServices = spatialServices; _reader = underlyingReader; var fieldCount = _reader.FieldCount; _geographyColumns = new bool[fieldCount]; _geometryColumns = new bool[fieldCount]; for (var i = 0; i < _reader.FieldCount; i++) { var fieldTypeName = _reader.GetDataTypeName(i); // Use EndsWith so that we just see the schema and type name, not the database name. if (fieldTypeName.EndsWith(GeographySqlType, StringComparison.Ordinal)) { _geographyColumns[i] = true; } else if (fieldTypeName.EndsWith(GeometrySqlType, StringComparison.Ordinal)) { _geometryColumns[i] = true; } } }
public override DbGeometry GeometryFromBinary(byte[] geometryBinary) { Check.NotNull <byte[]>(geometryBinary, nameof(geometryBinary)); return(DbSpatialServices.CreateGeometry((DbSpatialServices)this, (object)new DefaultSpatialServices.ReadOnlySpatialValues(DbGeometry.DefaultCoordinateSystemId, (string)null, geometryBinary, (string)null))); }
public override DbGeography GeographyFromProviderValue(object providerValue) { Check.NotNull <object>(providerValue, nameof(providerValue)); return(DbSpatialServices.CreateGeography((DbSpatialServices)this, (object)DefaultSpatialServices.CheckProviderValue(providerValue))); }
internal DbGeography(DbSpatialServices spatialServices, object spatialProviderValue) { this._spatialProvider = spatialServices; this._providerValue = spatialProviderValue; }
public override DbGeometry GeometryFromText(string geometryText) { Check.NotNull <string>(geometryText, nameof(geometryText)); return(DbSpatialServices.CreateGeometry((DbSpatialServices)this, (object)new DefaultSpatialServices.ReadOnlySpatialValues(DbGeometry.DefaultCoordinateSystemId, geometryText, (byte[])null, (string)null))); }