public static StoreItemCollection CreateStoreItemCollection( string ssdl, Version targetFrameworkVersion, IDbDependencyResolver resolver, out IList <EdmSchemaError> edmErrors) { if (ssdl == null) { throw new ArgumentNullException("ssdl"); } if (targetFrameworkVersion == null) { throw new ArgumentNullException("targetFrameworkVersion"); } if (!EntityFrameworkVersion.IsValidVersion(targetFrameworkVersion)) { throw new ArgumentException( string.Format(CultureInfo.CurrentCulture, Resources.ErrorNonValidTargetVersion, targetFrameworkVersion), "targetFrameworkVersion"); } using (var textReader = new StringReader(ssdl)) { using (var ssdlReader = XmlReader.Create(textReader)) { return(StoreItemCollection.Create(new[] { ssdlReader }, null, resolver, out edmErrors)); } } }
public string GetInitialModelContents(Version targetSchemaVersion) { Debug.Assert( EntityFrameworkVersion.IsValidVersion(targetSchemaVersion), "invalid schema version"); return(EdmUtils.CreateEdmxString(targetSchemaVersion, string.Empty, string.Empty, string.Empty)); }
/// <summary> /// Returns the FeatureState for the exposed foreign keys in the conceptual model feature /// </summary> internal static FeatureState GetForeignKeysInModelFeatureState(Version schemaVersion) { Debug.Assert(EntityFrameworkVersion.IsValidVersion(schemaVersion), "Invalid schema version."); return(schemaVersion == EntityFrameworkVersion.Version1 ? FeatureState.VisibleButDisabled : FeatureState.VisibleAndEnabled); }
/// <summary> /// Returns the FeatureState for the EntityContainers' TypeAccess attribute feature /// </summary> internal static FeatureState GetEntityContainerTypeAccessFeatureState(Version schemaVersion) { Debug.Assert(EntityFrameworkVersion.IsValidVersion(schemaVersion), "Invalid schema version."); return(schemaVersion > EntityFrameworkVersion.Version1 ? FeatureState.VisibleAndEnabled : FeatureState.VisibleButDisabled); }
/// <summary> /// Return the FeatureState for the Function Import mapping feature. /// </summary> internal static FeatureState GetFunctionImportMappingFeatureState(Version schemaVersion) { Debug.Assert(EntityFrameworkVersion.IsValidVersion(schemaVersion), "Invalid schema version."); return(schemaVersion > EntityFrameworkVersion.Version1 ? FeatureState.VisibleAndEnabled : FeatureState.VisibleButDisabled); }
/// <summary> /// Return the FeatureState for the UseStrongSpatialTypes feature. /// </summary> internal static FeatureState GetUseStrongSpatialTypesFeatureState(Version schemaVersion) { Debug.Assert(EntityFrameworkVersion.IsValidVersion(schemaVersion), "Invalid schema version."); return(schemaVersion > EntityFrameworkVersion.Version2 ? FeatureState.VisibleAndEnabled : FeatureState.VisibleButDisabled); }
public LegacyCodeGenerationDriver(LanguageOption language, Version targetEntityFrameworkVersion) { Debug.Assert( EntityFrameworkVersion.IsValidVersion(targetEntityFrameworkVersion), "invalid targetEntityFrameworkVersion"); _language = language; _targetEntityFrameworkVersion = targetEntityFrameworkVersion; }
public EntityStoreSchemaGeneratorDatabaseSchemaLoader(EntityConnection entityConnection, Version storeSchemaModelVersion) { Debug.Assert(entityConnection != null, "entityConnection != null"); Debug.Assert(entityConnection.State == ConnectionState.Closed, "expected closed connection"); Debug.Assert(EntityFrameworkVersion.IsValidVersion(storeSchemaModelVersion), "invalid version"); _connection = entityConnection; _storeSchemaModelVersion = storeSchemaModelVersion; }
/// <summary> /// Return the FeatureState for the GenerateUpdateViews feature /// </summary> internal static FeatureState GetGenerateUpdateViewsFeatureState(Version schemaVersion) { Debug.Assert(EntityFrameworkVersion.IsValidVersion(schemaVersion), "Invalid schema version."); // This attribute was added in v2 to support Reporting Services return(schemaVersion > EntityFrameworkVersion.Version1 ? FeatureState.VisibleAndEnabled : FeatureState.VisibleButDisabled); }
public static CodeGeneratorBase Create(LanguageOption language, Version targetEntityFrameworkVersion) { Debug.Assert( EntityFrameworkVersion.IsValidVersion(targetEntityFrameworkVersion), "invalid targetEntityFrameworkVersion"); return(targetEntityFrameworkVersion == EntityFrameworkVersion.Version1 ? (CodeGeneratorBase) new EntityClassGenerator(language) : new EntityCodeGenerator(language, targetEntityFrameworkVersion)); }
protected override void InitializeModelContents(Version targetSchemaVersion) { Debug.Assert(EntityFrameworkVersion.IsValidVersion(targetSchemaVersion)); Debug.Assert(_model == null, "overwriting already initialized edmx???"); _model = XDocument.Parse( _initialModelContentsFactory.GetInitialModelContents(targetSchemaVersion)); Debug.Assert( SchemaManager.GetSchemaVersion(_model.Root.Name.Namespace) == targetSchemaVersion, "Schema version should not change or we should not cache the document"); }
public static EdmItemCollection CreateAndValidateEdmItemCollection(string csdl, Version targetFrameworkVersion) { if (csdl == null) { throw new ArgumentNullException("csdl"); } if (targetFrameworkVersion == null) { throw new ArgumentNullException("targetFrameworkVersion"); } if (!EntityFrameworkVersion.IsValidVersion(targetFrameworkVersion)) { throw new ArgumentException( string.Format(CultureInfo.CurrentCulture, Resources.ErrorNonValidTargetVersion, targetFrameworkVersion), "targetFrameworkVersion"); } IList <EdmSchemaError> schemaErrors; EdmItemCollection edmItemCollection; using (var textReader = new StringReader(csdl)) { using (var xmlReader = XmlReader.Create(textReader)) { edmItemCollection = EdmItemCollection.Create(new[] { xmlReader }, null, out schemaErrors); } } if (schemaErrors.Count > 0) { throw new InvalidOperationException( String.Format( CultureInfo.CurrentCulture, Resources.ErrorCsdlNotValid, string.Join(Environment.NewLine, schemaErrors.Select(e => e.Message)))); } if (edmItemCollection.CsdlVersion() > targetFrameworkVersion) { throw new InvalidOperationException( String.Format( CultureInfo.CurrentCulture, Resources.TargetVersionSchemaVersionMismatch, edmItemCollection.CsdlVersion(), targetFrameworkVersion)); } return(edmItemCollection); }
private static MetadataWorkspace GetProviderSchemaMetadataWorkspace( IDbDependencyResolver resolver, string providerInvariantName, SystemDataCommon.DbConnection providerConnection, Version targetSchemaVersion) { Debug.Assert(resolver != null, "resolver != null"); Debug.Assert(!string.IsNullOrWhiteSpace(providerInvariantName), "providerInvarianName cannot be null or empty"); Debug.Assert(providerConnection != null, "providerConnection != null"); Debug.Assert(EntityFrameworkVersion.IsValidVersion(targetSchemaVersion), "invalid targetSchemaVersion"); string csdlName; string ssdlName; string mslName; if (targetSchemaVersion >= EntityFrameworkVersion.Version3) { csdlName = DbProviderManifest.ConceptualSchemaDefinitionVersion3; ssdlName = DbProviderManifest.StoreSchemaDefinitionVersion3; mslName = DbProviderManifest.StoreSchemaMappingVersion3; } else { csdlName = DbProviderManifest.ConceptualSchemaDefinition; ssdlName = DbProviderManifest.StoreSchemaDefinition; mslName = DbProviderManifest.StoreSchemaMapping; } var providerServices = resolver.GetService <DbProviderServices>(providerInvariantName); Debug.Assert(providerServices != null, "Trying to get unregistered provider."); var providerManifest = providerServices.GetProviderManifest( providerServices.GetProviderManifestToken(providerConnection)); var edmItemCollection = LoadEdmItemCollection(csdlName); var storeItemCollection = LoadStoreItemCollection(providerManifest, ssdlName); var mappingItemCollection = LoadMappingItemCollection(providerManifest, mslName, edmItemCollection, storeItemCollection); var workspace = new MetadataWorkspace( () => edmItemCollection, () => storeItemCollection, () => mappingItemCollection); // TODO: there is currently no public surface to do this (workitem 606 on codeplex) //// make the views generate here so we can wrap the provider schema problems //// in a ProviderIncompatibleException //ForceViewGeneration(workspace); return(workspace); }
// <summary> // Whether the given <paramref name="schemaVersion" /> is the latest version supported by the given // Entity Framework (i.e. EntityFramework.dll or System.Data.Entity.dll) <paramref name="assemblyVersion" /> // </summary> // <param name="schemaVersion">Version of the EF schema.</param> // <param name="assemblyVersion"> // Version of an Entity Framework (i.e. EntityFramework.dll or System.Data.Entity.dll) assembly. // </param> // <param name="targetNetFrameworkVersion"> // Targeted .NET Framework version. Used to distinguish EF5 from EF4 if the assembly version if 4.0.0.0. // </param> // <returns> // <c>True</c> if the given <paramref name="schemaVersion" /> is the latest version supported by the given // Entity Framework (i.e. EntityFramework.dll or System.Data.Entity.dll) <paramref name="assemblyVersion" />. // <c>False</c> otherwise. // </returns> public static bool IsSchemaVersionLatestForAssemblyVersion( Version schemaVersion, Version assemblyVersion, Version targetNetFrameworkVersion) { Debug.Assert(EntityFrameworkVersion.IsValidVersion(schemaVersion), "Invalid schema version"); Debug.Assert(assemblyVersion != null, "assemblyVersion != null"); if (assemblyVersion == Version4 && targetNetFrameworkVersion >= NetFrameworkVersioningHelper.NetFrameworkVersion4_5) { assemblyVersion = Version5Net45; } return ((schemaVersion == EntityFrameworkVersion.Version3 && assemblyVersion >= Version5Net45) || (schemaVersion == EntityFrameworkVersion.Version2 && (assemblyVersion >= Version4 && assemblyVersion <= Version5Net40)) || (schemaVersion == EntityFrameworkVersion.Version1 && assemblyVersion == Version1)); }
/// <summary> /// Creates an EntityConnection loaded with the providers metadata for the store schema. /// </summary> /// <param name="resolver">Resolver used to resolve provider services.</param> /// <param name="providerInvariantName">The provider invariant name.</param> /// <param name="connectionString">The connection for the providers connection.</param> /// <param name="targetSchemaVersion">The target Entity Framework schema version that is being targeted.</param> /// <returns>An EntityConnection that can query the ConceptualSchemaDefinition for the provider.</returns> /// <remarks>virtual for testing</remarks> public virtual EntityConnection Create( IDbDependencyResolver resolver, string providerInvariantName, string connectionString, Version targetSchemaVersion) { Debug.Assert(resolver != null, "resolver != null"); Debug.Assert(!string.IsNullOrWhiteSpace(providerInvariantName), "providerInvarianName cannot be null or empty"); Debug.Assert(!string.IsNullOrWhiteSpace(connectionString), "connectionString cannot be null or empty"); Debug.Assert(EntityFrameworkVersion.IsValidVersion(targetSchemaVersion), "invalid targetSchemaVersion"); SystemDataCommon.DbProviderFactory factory; try { factory = SystemDataCommon.DbProviderFactories.GetFactory(providerInvariantName); } catch (ArgumentException e) { throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, Resources_VersioningFacade.EntityClient_InvalidStoreProvider, providerInvariantName), e); } var providerConnection = factory.CreateConnection(); if (providerConnection == null) { throw new ProviderIncompatibleException( String.Format( CultureInfo.CurrentCulture, Resources_VersioningFacade.ProviderFactoryReturnedNullFactory, providerInvariantName)); } providerConnection.ConnectionString = connectionString; return(new EntityConnection( GetProviderSchemaMetadataWorkspace( resolver, providerInvariantName, providerConnection, targetSchemaVersion), providerConnection)); }
/// <summary> /// Creates an EntityConnection loaded with the providers metadata for the latest available store schema. /// Note that the targetEntityFrameworkVersion parameter uses internal EntityFramework version numbers as /// described in the <see cref="EntityFrameworkVersion" /> class. /// </summary> /// <param name="resolver">Resolver used to resolve provider services.</param> /// <param name="providerInvariantName">The provider invariant name.</param> /// <param name="connectionString">The connection for the providers connection.</param> /// <param name="maxAllowedSchemaVersion">The maximum allowed Entity Framework schema version that is being targeted.</param> /// <param name="storeSchemaModelVersion"> /// The version of the store schema model supported by the provider. Can be either v1 or v3 (store schema model in v2 did not change /// from v1, in v3 TVFs are supported and the provider needs to know how to handle Esql queries that ask for TVFs). /// Note that schema view artifacts themselves are v1 since there is nothing that is needed to ask for v3 concepts that /// cannot be expressed in v1 terms. /// **This value MUST NOT be used as the version of the model that will be created for the user (which can be /// any version regardless of this value), nor as the version of schema view artifacts (which is always v1) /// but rather it is a version of concepts we are asking the provider to return details for (to put it simply if this is v3 /// we will ask the provider about TVFs, otherwise this is v1 and we don't ask about TVFs)** /// </param> /// <returns>An EntityConnection that can query the ConceptualSchemaDefinition for the provider.</returns> /// <remarks>virtual for testing</remarks> public virtual EntityConnection Create( IDbDependencyResolver resolver, string providerInvariantName, string connectionString, Version maxAllowedSchemaVersion, out Version storeSchemaModelVersion) { Debug.Assert(resolver != null, "resolver != null"); Debug.Assert(!string.IsNullOrWhiteSpace(providerInvariantName), "providerInvarianName cannot be null or empty"); Debug.Assert(!string.IsNullOrWhiteSpace(connectionString), "connectionString cannot be null or empty"); Debug.Assert(EntityFrameworkVersion.IsValidVersion(maxAllowedSchemaVersion), "invalid maxAllowedSchemaVersion"); // We are going to try loading all versions of the store schema model starting from the newest. // The first version of the model that was shipped with EntityFrameworkVersions.Version1 and EntityFrameworkVersions.Version2 is the last one // we try, if it fails to load let the exception to propagate up to the caller. var versions = EntityFrameworkVersion .GetAllVersions() .Where(v => v > EntityFrameworkVersion.Version2 && v <= maxAllowedSchemaVersion) .OrderByDescending(v => v); foreach (var version in versions) { try { storeSchemaModelVersion = version; return (Create( resolver, providerInvariantName, connectionString, storeSchemaModelVersion)); } catch (Exception e) { // Ignore the exception with the current version and try the next one. if (!IsCatchableExceptionType(e)) { throw; } } } storeSchemaModelVersion = EntityFrameworkVersion.Version1; return(Create(resolver, providerInvariantName, connectionString, storeSchemaModelVersion)); }
public string GetInitialModelContents(Version targetSchemaVersion) { Debug.Assert( EntityFrameworkVersion.IsValidVersion(targetSchemaVersion), "invalid schema version"); if (_initialModelContents == null) { AddSchemaSpecificReplacements(_replacementsDictionary, targetSchemaVersion); var sb = new StringBuilder(_fileContentsTemplate); foreach (var pair in _replacementsDictionary) { sb.Replace(pair.Key, pair.Value); } _initialModelContents = sb.ToString(); } return(_initialModelContents); }
public EntityStoreSchemaGeneratorDatabaseSchemaLoader( EntityConnection entityConnection, Version storeSchemaModelVersion) { Debug.Assert(entityConnection != null, "entityConnection != null"); Debug.Assert(entityConnection.State == ConnectionState.Closed, "expected closed connection"); Debug.Assert(EntityFrameworkVersion.IsValidVersion(storeSchemaModelVersion), "invalid version"); _connection = entityConnection; _storeSchemaModelVersion = storeSchemaModelVersion; if (_connection != null && _connection.StoreConnection != null && string.Equals( _connection.StoreConnection.GetProviderInvariantName(), SqlServerInvariantName, StringComparison.Ordinal) && !SwitchOffMetadataMergeJoins()) { _addOptionMergeJoinInterceptor = new AddOptionMergeJoinInterceptor(); } }
/// <remarks>Internal for testing.</remarks> internal static void RetargetWithMetadataConverter(XDocument xdoc, Version targetSchemaVersion, MetadataConverterDriver converter) { Debug.Assert(xdoc != null, "xdoc != null"); Debug.Assert(EntityFrameworkVersion.IsValidVersion(targetSchemaVersion), "invalid target schema version"); var inputXml = new XmlDocument { PreserveWhitespace = true }; using (var reader = xdoc.CreateReader()) { inputXml.Load(reader); } var outputXml = converter.Convert(inputXml, targetSchemaVersion); if (outputXml != null) { // Dev10 Bug 550594: There is a bug in XmlEditor that prevents from deleting the root node // unless the root node has previous sibling (like a comment or Xml declaration). if (xdoc.Root.PreviousNode == null) { xdoc.Root.AddBeforeSelf(new XComment("")); } // update xml document with new root element xdoc.Root.Remove(); using (var reader = new XmlNodeReader(outputXml)) { var newDoc = XDocument.Load(reader); xdoc.Add(newDoc.Root); } // Do not reload artifact here // Until the transaction is committed, the XLinq representation of the parsed xml tree hasn't been generated yet. } }
public EntityStoreSchemaGeneratorDatabaseSchemaLoader( EntityConnection entityConnection, Version storeSchemaModelVersion) { Debug.Assert(entityConnection != null, "entityConnection != null"); Debug.Assert(entityConnection.State == ConnectionState.Closed, "expected closed connection"); Debug.Assert(EntityFrameworkVersion.IsValidVersion(storeSchemaModelVersion), "invalid version"); _connection = entityConnection; _storeSchemaModelVersion = storeSchemaModelVersion; var isSqlServer = false; try { if (_connection != null && _connection.StoreConnection != null && string.Equals( _connection.StoreConnection.GetProviderInvariantName(), SqlServerInvariantName, StringComparison.Ordinal)) { isSqlServer = true; } } catch (Exception) { // Several exceptions can be thrown from GetProviderInvariantName(). // Assume that the provider is not SqlServer unless we can confirm it is. } if (isSqlServer && !SwitchOffMetadataMergeJoins()) { _addOptionMergeJoinInterceptor = new AddOptionMergeJoinInterceptor(); } }
/// <summary> /// Populates an <see cref="IDictionary{TKey, TValue}" /> that is used to provide inputs to a text template. This method can be overridden in derived classes to provide custom inputs. /// These inputs are placed into the CallContext for use by the text template. /// </summary> /// <param name="context">The state of the current activity.</param> /// <param name="inputs">A dictionary that relates input names to input values for use by a text template.</param> protected override void OnGetTemplateInputs(NativeActivityContext context, IDictionary <string, object> inputs) { inputs.Add(EdmConstants.ssdlOutputName, SsdlInput.Get(context)); inputs.Add(EdmConstants.existingSsdlInputName, ExistingSsdlInput.Get(context)); var symbolResolver = context.GetExtension <SymbolResolver>(); var edmParameterBag = symbolResolver[typeof(EdmParameterBag).Name] as EdmParameterBag; if (edmParameterBag == null) { throw new InvalidOperationException(Resources.DatabaseCreation_ErrorNoEdmParameterBag); } // Find the TargetVersion parameter var targetFrameworkVersion = edmParameterBag.GetParameter <Version>(EdmParameterBag.ParameterName.TargetVersion); if (targetFrameworkVersion == null) { throw new InvalidOperationException( String.Format( CultureInfo.CurrentCulture, Resources.DatabaseCreation_ErrorNoParameterDefined, EdmParameterBag.ParameterName.TargetVersion.ToString())); } // Validate the TargetVersion parameter and add it as an input if (false == EntityFrameworkVersion.IsValidVersion(targetFrameworkVersion)) { throw new InvalidOperationException( String.Format(CultureInfo.CurrentCulture, Resources.DatabaseCreation_ErrorInvalidTargetVersion, targetFrameworkVersion)); } inputs.Add(EdmParameterBag.ParameterName.TargetVersion.ToString(), targetFrameworkVersion); // Add the Provider invariant name var providerInvariantName = edmParameterBag.GetParameter <string>(EdmParameterBag.ParameterName.ProviderInvariantName); if (String.IsNullOrEmpty(providerInvariantName)) { throw new InvalidOperationException( String.Format( CultureInfo.CurrentCulture, Resources.DatabaseCreation_ErrorNoParameterDefined, EdmParameterBag.ParameterName.ProviderInvariantName.ToString())); } inputs.Add(EdmParameterBag.ParameterName.ProviderInvariantName.ToString(), providerInvariantName); // Add the Provider manifest token (optional) var providerManifestToken = edmParameterBag.GetParameter <string>(EdmParameterBag.ParameterName.ProviderManifestToken); inputs.Add(EdmParameterBag.ParameterName.ProviderManifestToken.ToString(), providerManifestToken); // Add the Database Schema Name var databaseSchemaName = edmParameterBag.GetParameter <string>(EdmParameterBag.ParameterName.DatabaseSchemaName); if (String.IsNullOrEmpty(databaseSchemaName)) { throw new InvalidOperationException( String.Format( CultureInfo.CurrentCulture, Resources.DatabaseCreation_ErrorNoParameterDefined, EdmParameterBag.ParameterName.DatabaseSchemaName.ToString())); } inputs.Add(EdmParameterBag.ParameterName.DatabaseSchemaName.ToString(), databaseSchemaName); // Add the Database Name (Note: it's OK for this to be null e.g. some providers do not provide this) var databaseName = edmParameterBag.GetParameter <string>(EdmParameterBag.ParameterName.DatabaseName); inputs.Add(EdmParameterBag.ParameterName.DatabaseName.ToString(), databaseName); // Add the DDL Template Path (optional) var ddlTemplatePath = edmParameterBag.GetParameter <string>(EdmParameterBag.ParameterName.DDLTemplatePath); inputs.Add(EdmParameterBag.ParameterName.DDLTemplatePath.ToString(), ddlTemplatePath); }
internal override bool IsXmlValid() { // If there is a VSXmlModelProvider, we should be able to find a docdata for it. // In any other case, it doesn't matter whether there is document data or not. var docData = VSHelpers.GetDocData(PackageManager.Package, Uri.LocalPath); Debug.Assert( !(XmlModelProvider is VSXmlModelProvider) || docData != null, "Using a VSXmlModelProvider but docData is null for Artifact!"); try { XmlDocument xmldoc; if (docData != null) { var textLines = VSHelpers.GetVsTextLinesFromDocData(docData); Debug.Assert(textLines != null, "Failed to get IVSTextLines from docdata"); xmldoc = EdmUtils.SafeLoadXmlFromString(VSHelpers.GetTextFromVsTextLines(textLines)); } else { // If there is no docdata then attempt to create the XmlDocument from the internal // XLinq tree in the artifact xmldoc = new XmlDocument(); xmldoc.Load(XDocument.CreateReader()); } // For the most part, the Edmx schema version of an artifact should be in sync with the schema version // that is compatible with the project's target framework; except when the user adds an existing edmx to a project (the version could be different). // For all cases, we always want to validate using the XSD's version that matches the artifact's version. var documentSchemaVersion = base.SchemaVersion; Debug.Assert( EntityFrameworkVersion.IsValidVersion(documentSchemaVersion), "The EF Schema Version is not valid. Value:" + (documentSchemaVersion != null ? documentSchemaVersion.ToString() : "null")); // does the XML parse? If not, the load call below will throw if (EntityFrameworkVersion.IsValidVersion(documentSchemaVersion)) { var nsMgr = SchemaManager.GetEdmxNamespaceManager(xmldoc.NameTable, documentSchemaVersion); // Do XSD validation on the document. xmldoc.Schemas = EscherAttributeContentValidator.GetInstance(documentSchemaVersion).EdmxSchemaSet; var svec = new SchemaValidationErrorCollector(); // remove runtime specific lines // find the ConceptualModel Schema node RemoveRunTimeNode(xmldoc, "/edmx:Edmx/edmx:Configurations", nsMgr); RemoveRunTimeNode(xmldoc, "/edmx:Edmx/edmx:Runtime/edmx:ConceptualModels", nsMgr); RemoveRunTimeNode(xmldoc, "/edmx:Edmx/edmx:Runtime/edmx:StorageModels", nsMgr); RemoveRunTimeNode(xmldoc, "/edmx:Edmx/edmx:Runtime/edmx:Mappings", nsMgr); xmldoc.Validate(svec.ValidationCallBack); return(svec.ErrorCount == 0); } } catch { } return(false); }
protected override void Execute(NativeActivityContext context) { var edmItemCollection = CsdlInput.Get(context); if (edmItemCollection == null) { throw new InvalidOperationException(Resources.ErrorCouldNotFindCSDL); } var symbolResolver = context.GetExtension <SymbolResolver>(); var edmParameterBag = symbolResolver[typeof(EdmParameterBag).Name] as EdmParameterBag; if (edmParameterBag == null) { throw new InvalidOperationException(Resources.ErrorNoEdmParameterBag); } // Find the TargetVersion parameter var targetFrameworkVersion = edmParameterBag.GetParameter <Version>(EdmParameterBag.ParameterName.TargetVersion); if (targetFrameworkVersion == null) { throw new InvalidOperationException( String.Format( CultureInfo.CurrentCulture, Resources.ErrorNoParameterDefined, EdmParameterBag.ParameterName.TargetVersion.ToString())); } // Validate the TargetVersion parameter if (false == EntityFrameworkVersion.IsValidVersion(targetFrameworkVersion)) { throw new InvalidOperationException( String.Format(CultureInfo.CurrentCulture, Resources.ErrorNonValidTargetVersion, targetFrameworkVersion)); } // Construct the Code View inputs in a dictionary var inputs = new Dictionary <string, object> { { EdmConstants.csdlInputName, edmItemCollection } }; // Process the SSDL and MSL code views, feeding in the CSDL var ssdl = ProcessOutputGenerator <string>(OutputGeneratorType.Get(context), context, inputs); var msl = ProcessOutputGenerator <string>(MslOutputGeneratorType.Get(context), context, inputs); // Validate the SSDL, but catch any naming errors and throw a friendlier one var ssdlCollection = EdmExtension.CreateAndValidateStoreItemCollection( ssdl, targetFrameworkVersion, DependencyResolver.Instance, true); #if DEBUG // Validate the MSL in Debug mode IList <EdmSchemaError> mslErrors; EdmExtension.CreateStorageMappingItemCollection( edmItemCollection, ssdlCollection, msl, out mslErrors); if (mslErrors != null && mslErrors.Count > 0) { var errorSb = new StringBuilder(); errorSb.AppendLine("Encountered the following errors while validating the MSL:"); foreach (var error in mslErrors) { errorSb.AppendLine(error.Message); } Debug.Fail(errorSb.ToString()); } #endif // We are done processing, save off all the outputs for the next stage SsdlOutput.Set(context, ssdl); MslOutput.Set(context, msl); }