示例#1
0
        internal void ValidateAndCompileMappings(EntityDesignArtifactSet artifactSet, bool doEscherValidation)
        {
            var artifact = artifactSet.GetEntityDesignArtifact();

            // XSD prevents an EDMX from having both a DataServices node and a Runtime node
            // don't validate DataServices
            if (artifact != null &&
                artifact.DataServicesNodePresent)
            {
                return;
            }

            if (doEscherValidation)
            {
                EscherModelValidator.ValidateEscherModel(artifactSet, false);
            }
            else
            {
                EscherModelValidator.ClearErrors(artifactSet);
                if (artifact != null)
                {
                    artifact.SetValidityDirtyForErrorClass(ErrorClass.Escher_All, true);
                }
            }

            // validate using the schema version of this artifact as the target Entity Framework version
            new RuntimeMetadataValidator(this, artifactSet.SchemaVersion, DependencyResolver.Instance)
            .ValidateAndCompileMappings(artifactSet, artifactSet.ShouldDoRuntimeMappingValidation());
        }
 internal bool ShouldDoRuntimeMappingValidation()
 {
     foreach (var error in GetErrors(ErrorClass.Escher_All))
     {
         if (EscherModelValidator.IsSkipRuntimeValidationError(error))
         {
             return(false);
         }
     }
     return(true);
 }
        /// <summary>
        ///     This will do analysis to determine if a document should be opened
        ///     only in the XmlEditor.
        /// </summary>
        internal void DetermineIfArtifactIsStructurallySafe()
        {
            // XSD prevents an EDMX from having both a DataServices node and a Runtime node
            // don't validate DataServices EDMX files
            if (DataServicesNodePresent)
            {
                _isStructurallySafe = false;
                return;
            }

            // reset the value to true first - then determine if not safe below.
            _isStructurallySafe = true;
            var artifactSet = (EntityDesignArtifactSet)ArtifactSet;

            // Do escher validation.  Doing this lets us determine if we want to keep MSL validation errors
            // in the artifact set, or just ignore them.
            EscherModelValidator.ValidateEscherModel(artifactSet, true);

            var shouldValidateMappings = artifactSet.ShouldDoRuntimeMappingValidation();

            // now do runtime validation.  Always pass true to do mapping validation since we need these errors to determine safe-mode
            // use the schema version of this artifact as the target Entity Framework version
            new RuntimeMetadataValidator(ModelManager, SchemaVersion, DependencyResolver.Instance)
            .Validate(artifactSet);

            // scan all of the validation errors to see if we need to go into safe mode
            foreach (var ei in artifactSet.GetAllErrors())
            {
                if (EscherModelValidator.IsOpenInEditorError(ei) ||
                    RuntimeMetadataValidator.IsOpenInEditorError(ei, this))
                {
                    _isStructurallySafe = false;
                }
            }

            // the XML editor will "fix-up" parser errors for us, so we parse again just to be sure that there are none
            if (_isStructurallySafe && IsXmlValid() == false)
            {
                _isStructurallySafe = false;
            }
            else if (DesignerInfo == null ||
                     DesignerInfo.Diagrams == null)
            {
                // if the edmx file is missing Designer or Diagrams element it's not designer safe
                _isStructurallySafe = false;
            }
            else if (ConceptualModel == null ||
                     ConceptualModel.EntityContainerCount > 1)
            {
                // if the edmx file is missing ConceptualModel or it has multiple EntityContainers it's not designer safe
                _isStructurallySafe = false;
            }
            else if (MappingModel == null ||
                     StorageModel == null)
            {
                // if the edmx file is missing MappingModel or StorageModel it's not designer safe
                _isStructurallySafe = false;
            }

            //
            // now we decide if we need to clear out the MSL errors from runtime validation above
            //
            if (shouldValidateMappings == false && _isStructurallySafe)
            {
                artifactSet.ClearErrors(ErrorClass.Runtime_MSL);
                artifactSet.ClearErrors(ErrorClass.Runtime_ViewGen);
            }
        }