This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Merge branch 'master' into async

Conflicts:
	.gitignore
	test/EntityFramework/UnitTests/SqlServer/SqlSpatialDataReaderTests.cs
	test/EntityFramework/UnitTests/UnitTests.csproj
  • Loading branch information...
AndriySvyryd committed Jul 17, 2012
2 parents 3296a2d + bb0ffeb commit f0ce29aaa16e256bb0b51914d843ae2a301b69ca
Showing with 6,277 additions and 5,262 deletions.
  1. +1 −0 .gitignore
  2. +1 −0 src/EntityFramework.SqlServer/EntityFramework.SqlServer.csproj
  3. +6 −30 src/EntityFramework.SqlServer/SqlProviderServices.cs
  4. +12 −9 src/EntityFramework.SqlServer/SqlSpatialDataReader.cs
  5. +40 −24 src/EntityFramework.SqlServer/SqlSpatialServices.cs
  6. +3 −107 src/EntityFramework.SqlServer/SqlTypesAssembly.cs
  7. +137 −0 src/EntityFramework.SqlServer/SqlTypesAssemblyLoader.cs
  8. +1 −1 src/EntityFramework.SqlServerCompact/SqlCeProviderServices.cs
  9. +13 −5 src/EntityFramework/Config/AppConfigDependencyResolver.cs
  10. +2 −2 src/EntityFramework/Config/CompositeResolver`.cs
  11. +24 −9 src/EntityFramework/Config/DbConfiguration.cs
  12. +7 −26 src/EntityFramework/Config/DbConfigurationFinder.cs
  13. +1 −1 src/EntityFramework/Config/DbConfigurationLoader.cs
  14. +16 −10 src/EntityFramework/Config/DbConfigurationManager.cs
  15. +1 −1 src/EntityFramework/Config/DbConfigurationProxy.cs
  16. +1 −1 src/EntityFramework/Config/DbNullConfiguration.cs
  17. +27 −0 src/EntityFramework/Config/DefaultProviderServicesResolver.cs
  18. +0 −2 src/EntityFramework/Config/IDbDependencyResolver.cs
  19. +1 −1 src/EntityFramework/Config/IDbDependencyResolverExtensions.cs
  20. +39 −0 src/EntityFramework/Config/MigrationsConfigurationResolver.cs
  21. +1 −1 src/EntityFramework/Config/ProviderServicesFactory.cs
  22. +1 −1 src/EntityFramework/Config/ResolverChain.cs
  23. +22 −26 src/EntityFramework/Config/RootDependencyResolver.cs
  24. +1 −1 src/EntityFramework/Config/SingletonDependencyResolver.cs
  25. +22 −22 src/EntityFramework/Core/Common/CommandTrees/DefaultExpressionVisitor.cs
  26. +51 −51 src/EntityFramework/Core/Common/CommandTrees/ExpressionBuilder/Internal/ArgumentValidation.cs
  27. +48 −48 src/EntityFramework/Core/Common/CommandTrees/Internal/Patterns.cs
  28. +47 −15 src/EntityFramework/Core/Common/DbProviderServices.cs
  29. +775 −775 src/EntityFramework/Core/Common/EntitySql/CqlLexer.cs
  30. +6 −6 src/EntityFramework/Core/Common/EntitySql/CqlLexerHelpers.cs
  31. +1,567 −1,567 src/EntityFramework/Core/Common/EntitySql/CqlParser.cs
  32. +11 −11 src/EntityFramework/Core/Common/EntitySql/CqlQuery.cs
  33. +571 −571 src/EntityFramework/Core/Common/EntitySql/SemanticAnalyzer.cs
  34. +3 −16 src/EntityFramework/Core/Common/EntityUtil.cs
  35. +45 −45 src/EntityFramework/Core/Common/internal/DbTypeMap.cs
  36. +9 −9 src/EntityFramework/Core/Common/internal/materialization/recordstatescratchpad.cs
  37. +6 −6 src/EntityFramework/Core/EntityClient/EntityConnectionStringBuilder.cs
  38. +1 −1 src/EntityFramework/Core/EntityClient/Internal/EntityProviderServices.cs
  39. +3 −3 src/EntityFramework/Core/EntityKey.cs
  40. +20 −20 src/EntityFramework/Core/EntityModel/SchemaObjectModel/XmlSchemaResource.cs
  41. +12 −12 src/EntityFramework/Core/Mapping/FunctionImportMappingComposable.cs
  42. +3 −3 src/EntityFramework/Core/Mapping/StorageMappingItemCollection.cs
  43. +42 −42 src/EntityFramework/Core/Mapping/StorageMappingItemLoader.cs
  44. +19 −19 src/EntityFramework/Core/Mapping/Update/Internal/FunctionMappingTranslator.cs
  45. +3 −3 src/EntityFramework/Core/Mapping/Update/Internal/KeyManager.cs
  46. +9 −9 src/EntityFramework/Core/Mapping/Update/Internal/Propagator.JoinPropagator.cs
  47. +1 −1 src/EntityFramework/Core/Metadata/Edm/ItemCollection.cs
  48. +74 −74 src/EntityFramework/Core/Metadata/Edm/Provider/EdmProviderManifest.cs
  49. +3 −3 src/EntityFramework/Core/Metadata/Edm/RelationshipEndMember.cs
  50. +10 −10 src/EntityFramework/Core/Metadata/Edm/TypeUsage.cs
  51. +1 −1 src/EntityFramework/Core/Metadata/ObjectItemCollection.cs
  52. +12 −11 src/EntityFramework/Core/Metadata/ObjectLayer/ObjectItemAttributeAssemblyLoader.cs
  53. +8 −7 src/EntityFramework/Core/Metadata/ObjectLayer/ObjectItemConventionAssemblyLoader.cs
  54. +31 −31 src/EntityFramework/Core/Objects/ELinq/Funcletizer.cs
  55. +78 −78 src/EntityFramework/Core/Objects/ELinq/MethodCallTranslator.cs
  56. +7 −7 src/EntityFramework/Core/Objects/Internal/DataContractImplementor.cs
  57. +32 −32 src/EntityFramework/Core/Objects/Internal/EntityProxyFactory.cs
  58. +12 −12 src/EntityFramework/Core/Objects/Internal/EntityProxyTypeInfo.cs
  59. +20 −20 src/EntityFramework/Core/Objects/Internal/PocoPropertyAccessorStrategy.cs
  60. +3 −3 src/EntityFramework/Core/Objects/ObjectStateManager.cs
  61. +13 −13 src/EntityFramework/Core/Query/PlanCompiler/ApplyOpRules.cs
  62. +3 −3 src/EntityFramework/Core/Query/PlanCompiler/ConstrainedSortOpRules.cs
  63. +3 −3 src/EntityFramework/Core/Query/PlanCompiler/DistinctOpRules.cs
  64. +14 −14 src/EntityFramework/Core/Query/PlanCompiler/FilterOpRules.cs
  65. +5 −5 src/EntityFramework/Core/Query/PlanCompiler/GroupByOpRules.cs
  66. +15 −15 src/EntityFramework/Core/Query/PlanCompiler/JoinOpRules.cs
  67. +3 −3 src/EntityFramework/Core/Query/PlanCompiler/PrimitiveTypeVarInfo.cs
  68. +6 −6 src/EntityFramework/Core/Query/PlanCompiler/ProjectOpRules.cs
  69. +16 −16 src/EntityFramework/Core/Query/PlanCompiler/ScalarOpRules.cs
  70. +5 −5 src/EntityFramework/Core/Query/PlanCompiler/SetOpRules.cs
  71. +4 −4 src/EntityFramework/Core/Query/PlanCompiler/SingleRowOpRules.cs
  72. +3 −3 src/EntityFramework/Core/Query/PlanCompiler/SortOpRules.cs
  73. +11 −11 src/EntityFramework/Core/Query/PlanCompiler/Validator.cs
  74. +3 −1 src/EntityFramework/Database.cs
  75. +33 −33 src/EntityFramework/Edm/EdmPrimitiveType.cs
  76. +30 −30 src/EntityFramework/Edm/Serialization/Xml/Internal/Csdl/EdmModelCsdlSchemaWriter.cs
  77. +4 −4 src/EntityFramework/Edm/Serialization/Xml/Internal/Ssdl/DbModelSsdlHelper.cs
  78. +4 −0 src/EntityFramework/EntityFramework.csproj
  79. +2 −2 src/EntityFramework/Infrastructure/DbContextInfo.cs
  80. +8 −8 src/EntityFramework/Infrastructure/IDbModelCacheKey.cs
  81. +7 −7 src/EntityFramework/Infrastructure/IDbModelCacheKeyFactory.cs
  82. +16 −0 src/EntityFramework/Internal/ConfigFile/MigrationSqlGeneratorElement.cs
  83. +8 −0 src/EntityFramework/Internal/ConfigFile/ProviderElement.cs
  84. +20 −3 src/EntityFramework/Internal/DatabaseCreator.cs
  85. +6 −6 src/EntityFramework/Internal/DbSetDiscoveryService.cs
  86. +59 −59 src/EntityFramework/Internal/DefaultModelCacheKey.cs
  87. +25 −25 src/EntityFramework/Internal/DefaultModelCacheKeyFactory.cs
  88. +13 −13 src/EntityFramework/Internal/EntityEntries/InternalNestedPropertyEntry.cs
  89. +2 −1 src/EntityFramework/Internal/InternalContext.cs
  90. +3 −3 src/EntityFramework/Internal/LazyInternalConnection.cs
  91. +2 −3 src/EntityFramework/Internal/LazyInternalContext.cs
  92. +3 −3 src/EntityFramework/Internal/ModelHashCalculator.cs
  93. +41 −5 src/EntityFramework/Internal/ProviderConfig.cs
  94. +3 −3 src/EntityFramework/MigrateDatabaseToLatestVersion`.cs
  95. +14 −14 src/EntityFramework/Migrations/Builders/ColumnBuilder.cs
  96. +13 −13 src/EntityFramework/Migrations/Builders/TableBuilder.cs
  97. +37 −37 src/EntityFramework/Migrations/DbMigration.cs
  98. +13 −8 src/EntityFramework/Migrations/DbMigrationsConfiguration.cs
  99. +13 −11 src/EntityFramework/Migrations/DbMigrator.cs
  100. +6 −6 src/EntityFramework/Migrations/Design/CSharpMigrationCodeGenerator.cs
  101. +3 −3 src/EntityFramework/Migrations/Design/MigrationCodeGenerator.cs
  102. +45 −70 src/EntityFramework/Migrations/Design/ToolingFacade.cs
  103. +6 −6 src/EntityFramework/Migrations/Design/VisualBasicMigrationCodeGenerator.cs
  104. +12 −12 src/EntityFramework/Migrations/Edm/EdmXNames.cs
  105. +4 −4 src/EntityFramework/Migrations/History/HistoryRepository.cs
  106. +66 −66 src/EntityFramework/Migrations/Infrastructure/EdmModelDiffer.cs
  107. +8 −8 src/EntityFramework/Migrations/Model/AddForeignKeyOperation.cs
  108. +4 −4 src/EntityFramework/Migrations/Model/AddPrimaryKeyOperation.cs
  109. +17 −17 src/EntityFramework/Migrations/Model/ColumnModel.cs
  110. +4 −4 src/EntityFramework/Migrations/Model/CreateIndexOperation.cs
  111. +3 −3 src/EntityFramework/Migrations/Model/DropForeignKeyOperation.cs
  112. +4 −4 src/EntityFramework/Migrations/Model/DropPrimaryKeyOperation.cs
  113. +25 −25 src/EntityFramework/ModelConfiguration/Configuration/Mapping/EntityMappingTransformer.cs
  114. +5 −5 src/EntityFramework/ModelConfiguration/Configuration/Mapping/NotNullConditionConfiguration.cs
  115. +24 −24 src/EntityFramework/ModelConfiguration/Configuration/Mapping/Services/EntityMappingService.cs
  116. +11 −11 src/EntityFramework/ModelConfiguration/Configuration/ModelConfiguration.cs
  117. +7 −7 ...ework/ModelConfiguration/Configuration/Properties/Navigation/ForeignKeyConstraintConfiguration.cs
  118. +3 −3 ...Framework/ModelConfiguration/Configuration/Properties/Primitive/PrimitivePropertyConfiguration.cs
  119. +4 −4 src/EntityFramework/ModelConfiguration/Configuration/Types/EntityTypeConfiguration.cs
  120. +4 −4 src/EntityFramework/ModelConfiguration/Conventions/Edm/AssociationInverseDiscoveryConvention.cs
  121. +10 −10 src/EntityFramework/ModelConfiguration/Conventions/Edm/ComplexTypeDiscoveryConvention.cs
  122. +4 −4 src/EntityFramework/ModelConfiguration/Conventions/Edm/Db/ColumnOrderingConvention.cs
  123. +4 −4 src/EntityFramework/ModelConfiguration/Conventions/Edm/ForeignKeyDiscoveryConvention.cs
  124. +9 −9 ...tyFramework/ModelConfiguration/Conventions/Edm/ForeignKeyNavigationPropertyAttributeConvention.cs
  125. +4 −4 src/EntityFramework/ModelConfiguration/Conventions/Edm/OneToOneConstraintIntroductionConvention.cs
  126. +41 −41 src/EntityFramework/ModelConfiguration/Conventions/Sets/V1ConventionSet.cs
  127. +5 −5 src/EntityFramework/ModelConfiguration/Design/EnglishPluralizationService.cs
  128. +3 −3 src/EntityFramework/ModelConfiguration/Edm/Common/DataModelAnnotationExtensions.cs
  129. +7 −7 src/EntityFramework/ModelConfiguration/Edm/Db/DbDatabaseMetadataExtensions.cs
  130. +9 −9 src/EntityFramework/ModelConfiguration/Edm/Db/DbTableColumnMetadataExtensions.cs
  131. +3 −3 src/EntityFramework/ModelConfiguration/Edm/Db/DbTableMetadataExtensions.cs
  132. +12 −12 src/EntityFramework/ModelConfiguration/Edm/Db/Mapping/DbDatabaseMappingExtensions.cs
  133. +3 −3 src/EntityFramework/ModelConfiguration/Edm/Db/Mapping/DbEntityTypeMappingExtensions.cs
  134. +3 −3 src/EntityFramework/ModelConfiguration/Edm/EdmComplexTypeExtensions.cs
  135. +8 −8 src/EntityFramework/ModelConfiguration/Edm/EdmEntityTypeExtensions.cs
  136. +4 −4 src/EntityFramework/ModelConfiguration/Edm/EdmEnumTypeExtensions.cs
  137. +22 −22 src/EntityFramework/ModelConfiguration/Edm/EdmModelExtensions.cs
  138. +11 −11 src/EntityFramework/ModelConfiguration/Edm/EdmPropertyExtensions.cs
  139. +17 −17 src/EntityFramework/ModelConfiguration/Edm/Services/AssociationTypeMappingGenerator.cs
  140. +7 −7 src/EntityFramework/ModelConfiguration/Edm/Services/EntityTypeMappingGenerator.cs
  141. +3 −3 src/EntityFramework/ModelConfiguration/EntityTypeConfiguration.cs
  142. +6 −6 src/EntityFramework/ModelConfiguration/Mappers/PropertyMapper.cs
  143. +4 −4 src/EntityFramework/ModelConfiguration/Mappers/TypeMapper.cs
  144. +39 −80 src/EntityFramework/Properties/Resources.cs
  145. +15 −22 src/EntityFramework/Properties/Resources.resx
  146. +10 −34 src/EntityFramework/Spatial/DbSpatialServices.cs
  147. +10 −10 src/EntityFramework/Spatial/DefaultSpatialServices.cs
  148. +48 −0 src/EntityFramework/Spatial/SpatialServicesLoader.cs
  149. +3 −3 src/EntityFramework/Utilities/DbContextExtensions.cs
  150. +0 −1 src/EntityFramework/Utilities/DbProviderFactoryExtensions.cs
  151. +3 −3 src/EntityFramework/Utilities/PropertyInfoExtensions.cs
  152. +44 −0 src/EntityFramework/Utilities/TypeExtensions.cs
  153. +5 −0 src/NuGet/EntityFramework.SqlServerCompact/Content/App.config.transform
  154. +5 −0 src/NuGet/EntityFramework.SqlServerCompact/Content/Web.config.transform
  155. +2 −2 src/NuGet/EntityFramework.SqlServerCompact/EntityFramework.SqlServerCompact.nuspec
  156. +1 −2 src/NuGet/EntityFramework/EntityFramework.nuspec
  157. +2 −0 src/NuGet/NuGet.proj
  158. +11 −1 src/PowerTools/CodeTemplates/ReverseEngineerCodeFirst/Entity.tt
  159. +27 −0 src/PowerTools/Handlers/OptimizeContextHandler.cs
  160. +1 −1 test/EntityFramework/DropAllDatabases.sql
  161. +1 −1 test/EntityFramework/FunctionalTests/CodeFirst/ConventionsScenarioTests.cs
  162. +1 −1 test/EntityFramework/FunctionalTests/CodeFirst/DataServicesTests.cs
  163. +1 −1 test/EntityFramework/FunctionalTests/Migrations/TestHelpers/DbTestCase.cs
  164. +18 −5 test/EntityFramework/FunctionalTests/Migrations/TestHelpers/TestDatabase.cs
  165. +1 −1 test/EntityFramework/FunctionalTests/ProductivityApi/ConnectionTests.cs
  166. +3 −3 test/EntityFramework/FunctionalTests/ProductivityApi/DatabaseInitializationTests.cs
  167. +6 −11 test/EntityFramework/FunctionalTests/ProductivityApi/DbConnectionFactoryTests.cs
  168. +13 −6 test/EntityFramework/FunctionalTests/TestHelpers/FunctionalTestBase.cs
  169. +3 −1 test/EntityFramework/UnitTests/App.config
  170. +137 −46 test/EntityFramework/UnitTests/AppConfigTests.cs
  171. +62 −5 test/EntityFramework/UnitTests/Config/AppConfigDependencyResolverTests.cs
  172. +0 −37 test/EntityFramework/UnitTests/Config/DbConfigurationFinderTests.cs
  173. +62 −6 test/EntityFramework/UnitTests/Config/DbConfigurationTests.cs
  174. +61 −0 test/EntityFramework/UnitTests/Config/DefaultProviderServicesResolverTests.cs
  175. +46 −0 test/EntityFramework/UnitTests/Config/MigrationsConfigurationResolverTests.cs
  176. +30 −41 test/EntityFramework/UnitTests/Config/RootDependencyResolverTests.cs
  177. +85 −1 test/EntityFramework/UnitTests/Core/Common/DbProviderServicesTests.cs
  178. +0 −145 test/EntityFramework/UnitTests/DatabaseInitializationTests.cs
  179. +18 −0 test/EntityFramework/UnitTests/Internal/ConfigFile/MigrationSqlGeneratorElementTests.cs
  180. +19 −7 test/EntityFramework/UnitTests/Internal/ConfigFile/ProviderElementTests.cs
  181. +188 −0 test/EntityFramework/UnitTests/Internal/DatabaseCreatorTests.cs
  182. +1 −1 test/EntityFramework/UnitTests/ModelHashCalculatorTests.cs
  183. +18 −0 test/EntityFramework/UnitTests/Spatial/DbSpatialServicesTests.cs
  184. +70 −0 test/EntityFramework/UnitTests/Spatial/SpatialServicesLoaderTests.cs
  185. +4 −4 test/EntityFramework/UnitTests/SqlServer/SqlSpatialDataReaderTests.cs
  186. +58 −4 test/EntityFramework/UnitTests/SqlServer/SqlSpatialServicesTests.cs
  187. +39 −0 test/EntityFramework/UnitTests/SqlServer/SqlTypesAssemblyLoaderTests.cs
  188. +16 −0 test/EntityFramework/UnitTests/TestHelpers/Fake/FakeSqlGenerator.cs
  189. +1 −1 test/EntityFramework/UnitTests/TestHelpers/Fake/FakeSqlProviderServices.cs
  190. +8 −0 test/EntityFramework/UnitTests/UnitTests.csproj
  191. +211 −91 test/EntityFramework/UnitTests/Utilities/TypeExtensionsTests.cs
View
@@ -16,6 +16,7 @@ TestResults
packages
EntityFramework.xml
EntityFramework.SqlServer.xml
+EntityFramework.SqlServerCompact.xml
*.BASE.*
*.REMOTE.*
*.LOCAL.*
@@ -139,6 +139,7 @@
<Compile Include="SqlDdlBuilder.cs" />
<Compile Include="SqlGen\BoolWrapper.cs" />
<Compile Include="SqlGen\DmlSqlGenerator.cs" />
+ <Compile Include="SqlTypesAssemblyLoader.cs" />
<Compile Include="SqlVersionUtils.cs" />
<Compile Include="Utilities\DbExpressionExtensions.cs" />
<Compile Include="Utilities\EdmFunctionExtensions.cs" />
@@ -36,6 +36,8 @@ private SqlProviderServices()
/// </summary>
private static readonly SqlProviderServices _providerInstance = new SqlProviderServices();
+ private static readonly SqlTypesAssemblyLoader _sqlTypesAssemblyLoader = new SqlTypesAssemblyLoader();
+
/// <summary>
/// The Singleton instance of the SqlProviderServices type.
/// </summary>
@@ -49,7 +51,7 @@ public static SqlProviderServices Instance
/// </summary>
/// <param name="providerManifest">provider manifest that was determined from metadata</param>
/// <param name="commandTree">command tree for the statement</param>
- /// <returns>an exectable command definition object</returns>
+ /// <returns>an executable command definition object</returns>
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
protected override DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
{
@@ -263,7 +265,7 @@ protected override DbSpatialDataReader GetDbSpatialDataReader(DbDataReader fromR
{
throw new ProviderIncompatibleException(Strings.SqlProvider_NeedSqlDataReader(fromReader.GetType()));
}
- return new SqlSpatialDataReader(new SqlDataReaderWrapper(underlyingReader));
+ return new SqlSpatialDataReader(GetSpatialServices(versionHint), new SqlDataReaderWrapper(underlyingReader));
}
protected override DbSpatialServices DbGetSpatialServices(string versionHint)
@@ -289,32 +291,6 @@ private static void ValidateVersionHint(string versionHint)
}
}
- internal static SqlTypesAssembly GetSqlTypesAssembly()
- {
- SqlTypesAssembly sqlTypes;
- if (!TryGetSqlTypesAssembly(out sqlTypes))
- {
- throw new InvalidOperationException(Strings.SqlProvider_SqlTypesAssemblyNotFound);
- }
- Debug.Assert(sqlTypes != null);
- return sqlTypes;
- }
-
- internal static bool SqlTypesAssemblyIsAvailable
- {
- get
- {
- SqlTypesAssembly notUsed;
- return TryGetSqlTypesAssembly(out notUsed);
- }
- }
-
- private static bool TryGetSqlTypesAssembly(out SqlTypesAssembly sqlTypesAssembly)
- {
- sqlTypesAssembly = SqlTypesAssembly.Latest;
- return sqlTypesAssembly != null;
- }
-
/// <summary>
/// Creates a SqlParameter given a name, type, and direction
/// </summary>
@@ -453,14 +429,14 @@ internal static object EnsureSqlParameterValue(object value)
var geographyValue = value as DbGeography;
if (geographyValue != null)
{
- value = GetSqlTypesAssembly().ConvertToSqlTypesGeography(geographyValue);
+ value = _sqlTypesAssemblyLoader.GetSqlTypesAssembly().ConvertToSqlTypesGeography(geographyValue);
}
else
{
var geometryValue = value as DbGeometry;
if (geometryValue != null)
{
- value = GetSqlTypesAssembly().ConvertToSqlTypesGeometry(geometryValue);
+ value = _sqlTypesAssemblyLoader.GetSqlTypesAssembly().ConvertToSqlTypesGeometry(geometryValue);
}
}
}
@@ -16,12 +16,15 @@ namespace System.Data.Entity.SqlServer
/// </summary>
internal sealed class SqlSpatialDataReader : DbSpatialDataReader
{
+ private const string GeometrySqlType = "sys.geometry";
+ private const string GeographySqlType = "sys.geography";
+
+ private readonly DbSpatialServices _spatialServices;
private readonly SqlDataReaderWrapper _reader;
- private const string geometrySqlType = "sys.geometry";
- private const string geographySqlType = "sys.geography";
- internal SqlSpatialDataReader(SqlDataReaderWrapper underlyingReader)
+ internal SqlSpatialDataReader(DbSpatialServices spatialServices, SqlDataReaderWrapper underlyingReader)
{
+ _spatialServices = spatialServices;
_reader = underlyingReader;
}
@@ -30,7 +33,7 @@ public override DbGeography GetGeography(int ordinal)
EnsureGeographyColumn(ordinal);
var geogBytes = _reader.GetSqlBytes(ordinal);
var providerValue = _sqlGeographyFromBinaryReader.Value(new BinaryReader(geogBytes.Stream));
- return SqlSpatialServices.Instance.GeographyFromProviderValue(providerValue);
+ return _spatialServices.GeographyFromProviderValue(providerValue);
}
public override async Task<DbGeography> GetGeographyAsync(int ordinal, CancellationToken cancellationToken)
@@ -46,7 +49,7 @@ public override DbGeometry GetGeometry(int ordinal)
EnsureGeometryColumn(ordinal);
var geomBytes = _reader.GetSqlBytes(ordinal);
var providerValue = _sqlGeometryFromBinaryReader.Value(new BinaryReader(geomBytes.Stream));
- return SqlSpatialServices.Instance.GeometryFromProviderValue(providerValue);
+ return _spatialServices.GeometryFromProviderValue(providerValue);
}
public override async Task<DbGeometry> GetGeometryAsync(int ordinal, CancellationToken cancellationToken)
@@ -59,18 +62,18 @@ public override DbGeometry GetGeometry(int ordinal)
private static readonly Lazy<Func<BinaryReader, object>> _sqlGeographyFromBinaryReader =
new Lazy<Func<BinaryReader, object>>(
- () => CreateBinaryReadDelegate(SqlProviderServices.GetSqlTypesAssembly().SqlGeographyType), isThreadSafe: true);
+ () => CreateBinaryReadDelegate(new SqlTypesAssemblyLoader().GetSqlTypesAssembly().SqlGeographyType), isThreadSafe: true);
private static readonly Lazy<Func<BinaryReader, object>> _sqlGeometryFromBinaryReader =
new Lazy<Func<BinaryReader, object>>(
- () => CreateBinaryReadDelegate(SqlProviderServices.GetSqlTypesAssembly().SqlGeometryType), isThreadSafe: true);
+ () => CreateBinaryReadDelegate(new SqlTypesAssemblyLoader().GetSqlTypesAssembly().SqlGeometryType), isThreadSafe: true);
// test to ensure that the SQL column has the expected SQL type. Don't use the CLR type to avoid having to worry about differences in
// type versions between the client and the database.
private void EnsureGeographyColumn(int ordinal)
{
var fieldTypeName = _reader.GetDataTypeName(ordinal);
- if (!fieldTypeName.EndsWith(geographySqlType, StringComparison.Ordinal))
+ if (!fieldTypeName.EndsWith(GeographySqlType, StringComparison.Ordinal))
// Use EndsWith so that we just see the schema and type name, not the database name.
{
throw new InvalidDataException(Strings.SqlProvider_InvalidGeographyColumn(fieldTypeName));
@@ -80,7 +83,7 @@ private void EnsureGeographyColumn(int ordinal)
private void EnsureGeometryColumn(int ordinal)
{
var fieldTypeName = _reader.GetDataTypeName(ordinal);
- if (!fieldTypeName.EndsWith(geometrySqlType, StringComparison.Ordinal))
+ if (!fieldTypeName.EndsWith(GeometrySqlType, StringComparison.Ordinal))
// Use EndsWith so that we just see the schema and type name, not the database name.
{
throw new InvalidDataException(Strings.SqlProvider_InvalidGeometryColumn(fieldTypeName));
@@ -6,67 +6,83 @@
using System.Data.Entity.SqlServer.Utilities;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
+ using System.Diagnostics.Contracts;
using System.Reflection;
using System.Runtime.Serialization;
[Serializable]
internal sealed class SqlSpatialServices : DbSpatialServices, ISerializable
{
- /// <summary>
- /// Do not allow instantiation
- /// </summary>
- internal static readonly SqlSpatialServices Instance = new SqlSpatialServices(SqlProviderServices.GetSqlTypesAssembly);
+ internal static readonly SqlSpatialServices Instance
+ = new SqlSpatialServices(new SqlTypesAssemblyLoader(), l => l.GetSqlTypesAssembly());
- private static Dictionary<string, SqlSpatialServices> otherSpatialServices;
+ private static Dictionary<string, SqlSpatialServices> _otherSpatialServices;
[NonSerialized]
private readonly Lazy<SqlTypesAssembly> _sqlTypesAssemblySingleton;
- internal SqlSpatialServices()
+ [NonSerialized]
+ private readonly SqlTypesAssemblyLoader _sqlTypesAssemblyLoader;
+
+ public SqlSpatialServices()
{
}
- private SqlSpatialServices(Func<SqlTypesAssembly> getSqlTypes)
+ public SqlSpatialServices(SqlTypesAssemblyLoader sqlTypesAssemblyLoader, Func<SqlTypesAssemblyLoader, SqlTypesAssembly> getSqlTypes)
{
- Debug.Assert(getSqlTypes != null, "Validate SqlTypes assembly delegate before constructing SqlSpatialServiceS");
- _sqlTypesAssemblySingleton = new Lazy<SqlTypesAssembly>(getSqlTypes, isThreadSafe: true);
+ Contract.Requires(getSqlTypes != null);
+ Contract.Requires(sqlTypesAssemblyLoader != null);
- // Create Singletons that will delay-initialize the MethodInfo and PropertyInfo instances used to invoke SqlGeography/SqlGeometry methods via reflection.
+ _sqlTypesAssemblyLoader = sqlTypesAssemblyLoader;
+ _sqlTypesAssemblySingleton = new Lazy<SqlTypesAssembly>(() => getSqlTypes(sqlTypesAssemblyLoader), isThreadSafe: true);
+
+ // Create Singletons that will delay-initialize the MethodInfo and PropertyInfo instances
+ // used to invoke SqlGeography/SqlGeometry methods via reflection.
InitializeMemberInfo();
}
- private SqlSpatialServices(SerializationInfo info, StreamingContext context)
+ public SqlSpatialServices(SerializationInfo info, StreamingContext context)
+ {
+ _sqlTypesAssemblyLoader = Instance._sqlTypesAssemblyLoader;
+ _sqlTypesAssemblySingleton = Instance._sqlTypesAssemblySingleton;
+ InitializeMemberInfo(Instance);
+ }
+
+ /// <inheritdoc/>
+ public override bool NativeTypesAvailable
{
- var instance = Instance;
- _sqlTypesAssemblySingleton = instance._sqlTypesAssemblySingleton;
- InitializeMemberInfo(instance);
+ get
+ {
+ return _sqlTypesAssemblyLoader.TryGetSqlTypesAssembly() != null;
+ }
}
// Given an assembly purportedly containing SqlServerTypes for spatial values, attempt to
- // create a corersponding Sql spefic DbSpatialServices value backed by types from that assembly.
+ // create a corresponding SQL specific DbSpatialServices value backed by types from that assembly.
// Uses a dictionary to ensure that there is at most db spatial service per assembly. It's important that
// this be done in a way that ensures that the underlying SqlTypesAssembly value is also atomized,
// since that's caching compilation.
// Relies on SqlTypesAssembly to verify that the assembly is appropriate.
private static bool TryGetSpatialServiceFromAssembly(Assembly assembly, out SqlSpatialServices services)
{
- if (otherSpatialServices == null
- || !otherSpatialServices.TryGetValue(assembly.FullName, out services))
+ if (_otherSpatialServices == null
+ || !_otherSpatialServices.TryGetValue(assembly.FullName, out services))
{
lock (Instance)
{
- if (otherSpatialServices == null
- || !otherSpatialServices.TryGetValue(assembly.FullName, out services))
+ if (_otherSpatialServices == null
+ || !_otherSpatialServices.TryGetValue(assembly.FullName, out services))
{
SqlTypesAssembly sqlAssembly;
- if (SqlTypesAssembly.TryGetSqlTypesAssembly(assembly, out sqlAssembly))
+ var loader = new SqlTypesAssemblyLoader();
+ if (loader.TryGetSqlTypesAssembly(assembly, out sqlAssembly))
{
- if (otherSpatialServices == null)
+ if (_otherSpatialServices == null)
{
- otherSpatialServices = new Dictionary<string, SqlSpatialServices>(1);
+ _otherSpatialServices = new Dictionary<string, SqlSpatialServices>(1);
}
- services = new SqlSpatialServices(() => sqlAssembly);
- otherSpatialServices.Add(assembly.FullName, services);
+ services = new SqlSpatialServices(loader, l => sqlAssembly);
+ _otherSpatialServices.Add(assembly.FullName, services);
}
else
{
Oops, something went wrong.

0 comments on commit f0ce29a

Please sign in to comment.