internal override bool ValidateValueAgainstSchema()
 {
     if (EdmFeatureManager.GetUseStrongSpatialTypesFeatureState(Parent.Artifact.SchemaVersion).IsEnabled())
     {
         return(true);
     }
     return(false);
 }
 internal override bool ValidateValueAgainstSchema()
 {
     if (EdmFeatureManager.GetLazyLoadingFeatureState(Parent.Artifact.SchemaVersion).IsEnabled())
     {
         return(true);
     }
     return(false);
 }
 internal virtual string DescriptionGenerateUpdateViews()
 {
     if (!EdmFeatureManager.GetGenerateUpdateViewsFeatureState(TypedEFElement.Artifact.SchemaVersion).IsEnabled())
     {
         return(String.Format(
                    CultureInfo.CurrentCulture, "({0}) {1}", Resources.DisabledFeatureTooltip,
                    Resources.PropertyWindow_Description_GenerateUpdateViews));
     }
     return(Resources.PropertyWindow_Description_GenerateUpdateViews);
 }
Esempio n. 4
0
        internal static AssociationSummary ConstructAssociationSummary(EFArtifact artifact)
        {
            var ecm = artifact.MappingModel().FirstEntityContainerMapping;

            var summary = new AssociationSummary();

            if (!EdmFeatureManager.GetForeignKeysInModelFeatureState(artifact.SchemaVersion).IsEnabled())
            {
                if (ecm != null)
                {
                    // Foreign keys in the model are not supported for this EDMX version.
                    foreach (var asm in ecm.AssociationSetMappings())
                    {
                        var cSideAssociation = asm.TypeName.Target;

                        if (null != cSideAssociation)
                        {
                            var assocId = AssociationIdentityForAssociationSetMapping.CreateAssociationIdentity(asm);
                            if (null != assocId)
                            {
                                summary.Add(cSideAssociation, assocId);
                            }
                        }
                    }
                }
            }
            else
            {
                // Foreign keys in the model are supported for this EDMX version.
                foreach (var a in artifact.ConceptualModel().Associations())
                {
                    AssociationIdentity assocId = null;
                    if (a.IsManyToMany == false &&
                        a.ReferentialConstraint != null)
                    {
                        assocId = AssociationIdentityForReferentialConstraint.CreateAssociationIdentity(a.ReferentialConstraint);
                    }
                    else
                    {
                        var asm = ModelHelper.FindAssociationSetMappingForConceptualAssociation(a);
                        if (asm != null)
                        {
                            assocId = AssociationIdentityForAssociationSetMapping.CreateAssociationIdentity(asm);
                        }
                    }
                    if (null != assocId)
                    {
                        summary.Add(a, assocId);
                    }
                }
            }
            return(summary);
        }
Esempio n. 5
0
        private IEnumerable <Property> GetMappableDependentProperties()
        {
            IEnumerable <Property> rtrn;

            if (_dependent == null)
            {
                rtrn = new Property[0];
            }
            else if (_association.EntityModel.IsCSDL == false)
            {
                // in the SSDL, ref constraints can be to non-key columns
                rtrn = _dependent.Type.Target.Properties();
            }
            else if (EdmFeatureManager.GetForeignKeysInModelFeatureState(_association.Artifact.SchemaVersion).IsEnabled())
            {
                // targeting netfx 4.0 or greater, so allow all properties on the dependent end
                var l = new List <Property>();
                var t = _dependent.Type.Target as ConceptualEntityType;
                Debug.Assert(_dependent.Type.Target == null || t != null, "EntityType is not ConceptualEntityType");
                while (t != null)
                {
                    foreach (var p in t.Properties())
                    {
                        if ((p is ComplexConceptualProperty) == false)
                        {
                            l.Add(p);
                        }
                    }
                    t = t.BaseType.Target;
                }
                rtrn = l;
            }
            else
            {
                // targeting netfx 3.5, so allow only allow keys on the dependent end
                if (_dependent.Type.Target != null)
                {
                    var cet = _dependent.Type.Target as ConceptualEntityType;
                    Debug.Assert(cet != null, "entity type is not a conceptual entity type");
                    rtrn = cet.ResolvableTopMostBaseType.ResolvableKeys;
                }
                else
                {
                    rtrn = new Property[0];
                }
            }
            return(rtrn);
        }
Esempio n. 6
0
        internal static ICollection <EntityStoreSchemaFilterEntry> GetFunctionsFilterEntries(
            ModelBuilderSettings settings, DoWorkEventArgs args)
        {
            ICollection <EntityStoreSchemaFilterEntry> entries;

            if (EdmFeatureManager.GetComposableFunctionImportFeatureState(settings.TargetSchemaVersion).IsEnabled())
            {
                entries = ExecuteDatabaseMetadataQuery(
                    SelectFunctionsESqlQuery, EntityStoreSchemaFilterObjectTypes.Function, settings, args);
            }
            else
            {
                entries = ExecuteDatabaseMetadataQuery(
                    SelectFunctionsESqlQueryBeforeV3, EntityStoreSchemaFilterObjectTypes.Function, settings, args);
            }

            return(entries);
        }
        public ExplorerConceptualEntityModel(EditingContext context, ConceptualEntityModel entityModel, ExplorerEFElement parent)
            : base(context, entityModel, parent)
        {
            _typesGhostNode = new ExplorerTypes(
                Resources.ConceptualTypesGhostNodeName, context, this);
            _complexTypesGhostNode = new ExplorerComplexTypes(Resources.ComplexTypesGhostNodeName, context, this);
            _assocsGhostNode       = new ExplorerAssociations(
                Resources.ConceptualAssociationsGhostNodeName, context, this);
            _funcImportsGhostNode = new ExplorerFunctionImports(
                Resources.FunctionImportsGhostNodeName, context, this);

            _enumTypesGhostNode = null;

            if (EdmFeatureManager.GetEnumTypeFeatureState(entityModel.Artifact).IsEnabled())
            {
                _enumTypesGhostNode = new ExplorerEnumTypes(
                    Resources.EnumTypesGhostNodeName, context, this);
            }
        }
Esempio n. 8
0
        // <summary>
        //     Calls a validation method to check if this association's MSL is editable by the designer
        // </summary>
        private bool CanEditMappingsForFunctionImport(FunctionImport fi)
        {
            var errorMessage = string.Empty;

            // check whether we should lit up the function import mapping.
            if (EdmFeatureManager.GetFunctionImportMappingFeatureState(fi.Artifact.SchemaVersion).IsEnabled() == false)
            {
                SetWatermarkInfo(Resources.MappingDetails_ErrMappingNotSupported);
                return(false);
            }
            else if (MappingViewModelHelper.CanEditMappingsForFunctionImport(fi, ref errorMessage))
            {
                return(true);
            }
            else
            {
                SetWatermarkInfo(string.Format(CultureInfo.CurrentCulture, Resources.MappingDetails_ErrMslGeneral, errorMessage));
                return(false);
            }
        }
Esempio n. 9
0
        internal ReferentialConstraintDialog(Association association)
        {
            if (association == null)
            {
                // this should never be null on current code-paths.
                throw new ArgumentNullException("association");
            }

            _association = association;
            _end1        = _association.AssociationEnds()[0];
            _end2        = _association.AssociationEnds()[1];

            var selfAssociation = (_end1.Type.Target == _end2.Type.Target);

            _roleListItems.Add(_end1, new RoleListItem(_end1, selfAssociation));
            _roleListItems.Add(_end2, new RoleListItem(_end2, selfAssociation));

            InitializeComponent();

            // enable tool tips
            listMappings.ShowItemToolTips = true;

            if (EdmFeatureManager.GetForeignKeysInModelFeatureState(association.Artifact.SchemaVersion).IsEnabled())
            {
                hdrDependent.Text = DialogsResource.RefConstraintDialog_DependentKeyHeader_SupportFKs;
            }

            // Set the default font to VS shell font.
            var vsFont = VSHelpers.GetVSFont(Services.ServiceProvider);

            if (vsFont != null)
            {
                Font = vsFont;
            }

            // load list of roles
            cmdPrincipalRole.Items.Add(_blankRoleListItem);
            cmdPrincipalRole.Items.Add(_roleListItems[_end1]);
            cmdPrincipalRole.Items.Add(_roleListItems[_end2]);
        }
Esempio n. 10
0
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            Debug.Assert(FunctionImport != null, "InvokeInternal is called when FunctionImport is null");
            // safety check, this should never be hit
            if (FunctionImport == null)
            {
                throw new InvalidOperationException("InvokeInternal is called when FunctionImport is null");
            }

            FunctionImportNameOld = FunctionImport.Name.Value;
            FunctionOld           = FunctionImport.Function;
            if (FunctionImport.IsReturnTypeComplexType)
            {
                ReturnSingleTypeOld = FunctionImport.ReturnTypeAsComplexType;
            }
            else if (FunctionImport.IsReturnTypeEntityType)
            {
                ReturnSingleTypeOld = FunctionImport.ReturnTypeAsEntityType;
            }
            else
            {
                ReturnSingleTypeOld = FunctionImport.ReturnTypeAsPrimitiveType.Value;
            }

            UpdateFunctionImportName();

            // only change IsComposable if artifact has high enough schema version to support it
            if (EdmFeatureManager.GetComposableFunctionImportFeatureState(FunctionImport.Artifact.SchemaVersion)
                .IsEnabled())
            {
                UpdateFunctionImportIsComposable(cpc);
            }

            UpdateFunctionImportFunction(cpc);
            UpdateFunctionImportReturnType(cpc);
        }
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            // safety check, this should never be hit
            if (Container == null ||
                (Function == null && ParameterDefinitions == null) ||
                ReturnSingleType == null)
            {
                throw new InvalidOperationException(
                          "InvokeInternal is called when Container or Function or ParameterDefinitions or ReturnSingleType is null");
            }

            _fi = new FunctionImport(Container, null);
            _fi.LocalName.Value = FunctionImportName;

            // if we are using a high enough EDMX schema version then set IsComposable attribute
            if (EdmFeatureManager.GetComposableFunctionImportFeatureState(_fi.Artifact.SchemaVersion).IsEnabled())
            {
                // if Function.IsComposable is true set _fi.IsComposable to true also, but if it's false then
                // leave _fi.IsComposable unset which is equivalent to false
                if (Function.IsComposable.Value)
                {
                    _fi.IsComposable.Value = BoolOrNone.TrueValue;
                }
            }

            // if the return type is an EntityType, set the EntitySet attribute to
            // that EntityType's EntitySet. For other functions, don't set
            // the EntitySet.
            var returnSingleTypeString      = ReturnSingleType as string;
            var returnSingleTypeComplexType = ReturnSingleType as ComplexType;
            var returnSingleTypeEntity      = ReturnSingleType as EntityType;

            Debug.Assert(
                returnSingleTypeString != null || returnSingleTypeComplexType != null || returnSingleTypeEntity != null,
                "Return Type for function import must be of type string or ComplexType or EntityType");

            if (returnSingleTypeString != null)
            {
                // make sure that this is a primitive type or a complex type and build a "Collection()" around it.
                if (returnSingleTypeString != Tools.XmlDesignerBase.Resources.NoneDisplayValueUsedForUX)
                {
                    var edmPrimitiveTypes = ModelHelper.AllPrimitiveTypes(_fi.Artifact.SchemaVersion);
                    if (!edmPrimitiveTypes.Contains(returnSingleTypeString))
                    {
                        var msg = string.Format(CultureInfo.CurrentCulture, Resources.INVALID_FORMAT, returnSingleTypeString);
                        throw new CommandValidationFailedException(msg);
                    }

                    _fi.ReturnTypeAsPrimitiveType.Value = String.Format(
                        CultureInfo.InvariantCulture, FunctionImport.CollectionFormat, returnSingleTypeString);
                }
            }
            else if (returnSingleTypeComplexType != null)
            {
                var complexTypes = _fi.Artifact.ConceptualModel().ComplexTypes();
                if (!complexTypes.Contains(returnSingleTypeComplexType))
                {
                    var msg = string.Format(
                        CultureInfo.CurrentCulture, Resources.INVALID_FORMAT, returnSingleTypeComplexType.NormalizedNameExternal);
                    throw new CommandValidationFailedException(msg);
                }

                _fi.ReturnTypeAsComplexType.SetRefName(returnSingleTypeComplexType);
            }
            else if (returnSingleTypeEntity != null)
            {
                _fi.EntitySet.SetRefName(returnSingleTypeEntity.EntitySet);
                _fi.ReturnTypeAsEntityType.SetRefName(returnSingleTypeEntity);
            }

            Container.AddFunctionImport(_fi);
            XmlModelHelper.NormalizeAndResolve(_fi);

            if (ParameterDefinitions != null)
            {
                UpdateFunctionImportParameters(cpc, _fi, ParameterDefinitions);
            }
            if (Function != null)
            {
                UpdateFunctionImportParameters(cpc, _fi, Function);
            }
        }
Esempio n. 12
0
        internal NewAssociationDialog(IEnumerable <EntityType> entityTypes, EntityType entity1, EntityType entity2)
        {
            Debug.Assert(entity1 != null && entity2 != null, "both entity1 and entity2 should be non-null");

            // Ensure _foreignKeysSupported is intialized before we initialize UI components.
            _foreignKeysSupported =
                EdmFeatureManager.GetForeignKeysInModelFeatureState(entity1.Artifact.SchemaVersion)
                .IsEnabled();

            // pluralization service is based on English only for Dev10
            var pluralize = ModelHelper.GetDesignerPropertyValueFromArtifactAsBool(
                OptionsDesignerInfo.ElementName,
                OptionsDesignerInfo.AttributeEnablePluralization, OptionsDesignerInfo.EnablePluralizationDefault, entity1.Artifact);

            if (pluralize)
            {
                _pluralizationService = DependencyResolver.GetService <IPluralizationService>();
            }

            InitializeComponent();

            // Set the default font to VS shell font.
            var vsFont = VSHelpers.GetVSFont(Services.ServiceProvider);

            if (vsFont != null)
            {
                Font = vsFont;
            }

            foreach (var entityType in entityTypes)
            {
                entity1ComboBox.Items.Add(entityType);
                entity2ComboBox.Items.Add(entityType);
            }

            multiplicity1ComboBox.Items.Add(
                new MultiplicityComboBoxItem(Resources.PropertyWindow_Value_MultiplicityOne, ModelConstants.Multiplicity_One));
            multiplicity1ComboBox.Items.Add(
                new MultiplicityComboBoxItem(Resources.PropertyWindow_Value_MultiplicityZeroOrOne, ModelConstants.Multiplicity_ZeroOrOne));
            multiplicity1ComboBox.Items.Add(
                new MultiplicityComboBoxItem(Resources.PropertyWindow_Value_MultiplicityMany, ModelConstants.Multiplicity_Many));

            multiplicity2ComboBox.Items.Add(
                new MultiplicityComboBoxItem(Resources.PropertyWindow_Value_MultiplicityOne, ModelConstants.Multiplicity_One));
            multiplicity2ComboBox.Items.Add(
                new MultiplicityComboBoxItem(Resources.PropertyWindow_Value_MultiplicityZeroOrOne, ModelConstants.Multiplicity_ZeroOrOne));
            multiplicity2ComboBox.Items.Add(
                new MultiplicityComboBoxItem(Resources.PropertyWindow_Value_MultiplicityMany, ModelConstants.Multiplicity_Many));

            // set multiplicity and entity values first before adding event handlers, otherwise
            // it tries to update the ExplanationText and calculate NavProp names before all
            // of the required information is in place
            multiplicity1ComboBox.SelectedIndex         = 0;
            multiplicity2ComboBox.SelectedIndex         = 2;
            entity1ComboBox.SelectedItem                = entity1;
            entity2ComboBox.SelectedItem                = entity2;
            multiplicity1ComboBox.SelectedIndexChanged += multiplicity1ComboBox_SelectedIndexChanged;
            multiplicity2ComboBox.SelectedIndexChanged += multiplicity2ComboBox_SelectedIndexChanged;
            entity1ComboBox.SelectedIndexChanged       += entity1ComboBox_SelectedIndexChanged;
            entity2ComboBox.SelectedIndexChanged       += entity2ComboBox_SelectedIndexChanged;

            // now update the calculated fields
            UpdateAssociationName();
            UpdateEnd1NavigationPropertyName();
            UpdateEnd2NavigationPropertyName();
            UpdateExplanationText();
            UpdateCreateForeignKeysCheckBox();

            cancelButton.BackColor = SystemColors.Control;
            cancelButton.ForeColor = SystemColors.ControlText;
            okButton.BackColor     = SystemColors.Control;
            okButton.ForeColor     = SystemColors.ControlText;
        }
Esempio n. 13
0
        public void Invoke()
        {
            Debug.Assert(_association != null, "The Association reference is null");

            // if the association was deleted in this transaction, just return since we won't need to process it
            if (_association == null ||
                _association.XObject == null)
            {
                return;
            }

            // if foreign keys aren't supported in this EF version, then we skip all processing here.
            if (!EdmFeatureManager.GetForeignKeysInModelFeatureState(_association.Artifact.SchemaVersion).IsEnabled())
            {
                return;
            }

            Debug.Assert(_association.EntityModel.IsCSDL, "Creating foreign key properties isn't valid for SSDL associations");
            Debug.Assert(
                _association.AssociationEnds().Count == 2,
                "The association to be processed does not have 2 ends while trying to create foreign key properties");
            Debug.Assert(
                _association.AssociationSet != null,
                "The association being processed does not have a valid AssociationSet while trying to create foreign key properties");

            // remove any existing RC
            if (_association.ReferentialConstraint != null)
            {
                DeleteEFElementCommand.DeleteInTransaction(_context, _association.ReferentialConstraint);
            }

            // figure out the principal and dependent ends
            AssociationEnd principal = null;
            AssociationEnd dependent = null;

            ModelHelper.DeterminePrincipalDependentAssociationEnds(
                _association, out principal, out dependent,
                ModelHelper.DeterminePrincipalDependentAssociationEndsScenario.CreateForeignKeyProperties);

            if (principal != null &&
                principal.Type.Target != null &&
                dependent != null &&
                dependent.Type.Target != null)
            {
                // many-to-many associations don't need foreign key properties
                if (principal.Multiplicity.Value == ModelConstants.Multiplicity_Many &&
                    dependent.Multiplicity.Value == ModelConstants.Multiplicity_Many)
                {
                    return;
                }

                var principalPropertyRefs = new HashSet <Property>();
                var dependentPropertyRefs = new HashSet <Property>();

                // add properties to the dependent side

                IEnumerable <Property> pkeys;
                var cet = principal.Type.Target as ConceptualEntityType;
                if (cet != null)
                {
                    // the principal is a c-side entity
                    pkeys = cet.ResolvableTopMostBaseType.ResolvableKeys;
                }
                else
                {
                    // the principal is an s-side entity
                    pkeys = principal.Type.Target.ResolvableKeys;
                }

                foreach (var pkey in pkeys)
                {
                    // build up the foreign key name, add an '_' if the resulting name wouldn't be camel-case
                    // e.g.
                    //  Order and Id become "OrderId"
                    //  order and id become "order_id"
                    //
                    // get a unique name for this new property
                    var fkeyName = string.Format(
                        CultureInfo.CurrentCulture, "{0}{1}{2}",
                        principal.Type.Target.LocalName.Value,
                        (char.IsUpper(pkey.LocalName.Value, 0) ? "" : "_"),
                        pkey.LocalName.Value);
                    fkeyName = ModelHelper.GetUniqueName(typeof(Property), dependent.Type.Target, fkeyName);

                    // tweak the properties; we are using the copy/paste process since we have to
                    // copy all facets of the pk and that code does this already
                    var pcf = new PropertyClipboardFormat(pkey);
                    pcf.PropertyName          = fkeyName;
                    pcf.IsKeyProperty         = false;
                    pcf.IsNullable            = (principal.Multiplicity.Value == ModelConstants.Multiplicity_ZeroOrOne ? true : false);
                    pcf.StoreGeneratedPattern = string.Empty;
                    pcf.GetterAccessModifier  = string.Empty;
                    pcf.SetterAccessModifier  = string.Empty;

                    // create the new property
                    var cmd = new CopyPropertyCommand(pcf, dependent.Type.Target);
                    CommandProcessor.InvokeSingleCommand(_context, cmd);
                    var fkey = cmd.Property;

                    // build up our list of keys
                    Debug.Assert(fkey != null, "CreateForeignKeyProperties was not able to create a foreign key");
                    if (fkey != null)
                    {
                        principalPropertyRefs.Add(pkey);
                        dependentPropertyRefs.Add(fkey);
                    }
                }

                // create the new RC
                Debug.Assert(
                    principalPropertyRefs.Count == dependentPropertyRefs.Count,
                    "List of keys are mismatched while trying to create a Ref Constraint");
                if (principalPropertyRefs.Count > 0 &&
                    dependentPropertyRefs.Count > 0 &&
                    principalPropertyRefs.Count == dependentPropertyRefs.Count)
                {
                    var cmd = new CreateReferentialConstraintCommand(principal, dependent, principalPropertyRefs, dependentPropertyRefs);
                    CommandProcessor.InvokeSingleCommand(_context, cmd);
                }
            }
        }
        internal static bool CanEditMappingsForAssociation(
            Association association, MappingDetailsWindowContainer windowContainer, ref TreeGridDesignerWatermarkInfo watermarkInfo,
            bool allowMappingEditWithFKs)
        {
            if (association == null)
            {
                throw new ArgumentNullException("association");
            }

            // make sure that we have an EntitySet (or can find one)
            if (association.AssociationSet == null)
            {
                var errorMessage = String.Format(
                    CultureInfo.CurrentCulture, Resources.MappingDetails_ErrMslGeneral,
                    Resources.MappingDetails_ErrMslCantFindAssociationSet);
                watermarkInfo = new TreeGridDesignerWatermarkInfo(errorMessage);
                return(false);
            }

            var asms = association.AssociationSet.GetAntiDependenciesOfType <AssociationSetMapping>();

            var rc = association.ReferentialConstraint;

            if (rc != null)
            {
                // allowMappingEditWithFKs is an override flag that suppresses the following watermarks.
                if (allowMappingEditWithFKs == false)
                {
                    if (EdmFeatureManager.GetForeignKeysInModelFeatureState(association.Artifact.SchemaVersion)
                        .IsEnabled())
                    {
                        // set up watermarks association mapping window watermarks when FKs are supported
                        if (rc.IsPrimaryKeyToPrimaryKey())
                        {
                            if (asms.Count > 0)
                            {
                                watermarkInfo = CreateWatermarkInfoPKToPKRC_WithASM(windowContainer);
                            }
                            else
                            {
                                watermarkInfo = CreateWatermarkInfoPKToPKRC_NoASM(windowContainer);
                            }
                            return(false);
                        }
                        else
                        {
                            if (asms.Count > 0)
                            {
                                watermarkInfo = CreateWatermarkInfoPKToFKRC_WithASM(windowContainer);
                            }
                            else
                            {
                                watermarkInfo = CreateWatermarkInfoPKToFKRC_NoASM();
                            }
                            return(false);
                        }
                    }
                    else
                    {
                        // targeting netfx 3.5.  FKs are not supported
                        if (rc.IsPrimaryKeyToPrimaryKey() == false)
                        {
                            if (asms.Count > 0)
                            {
                                watermarkInfo = CreateWatermarkInfoPKToFKRC_WithASM(windowContainer);
                            }
                            else
                            {
                                watermarkInfo = CreateWatermarkInfoPKToFKRC_NoASM();
                            }
                            return(false);
                        }
                    }
                }
            }

            // make sure that there is just one AssociationSetMapping for our set
            if (asms.Count > 1)
            {
                var errorMessage = String.Format(
                    CultureInfo.CurrentCulture, Resources.MappingDetails_ErrMslGeneral,
                    Resources.MappingDetails_ErrMslTooManyAssociationSetMappings);
                watermarkInfo = new TreeGridDesignerWatermarkInfo(errorMessage);
                return(false);
            }
            else
            {
                foreach (var asm in asms)
                {
                    // if AssociationSetMapping contains QueryView
                    if (asm.HasQueryViewElement)
                    {
                        var errorMessage = String.Format(
                            CultureInfo.CurrentCulture, Resources.MappingDetails_ErrMslGeneral,
                            Resources.MappingDetails_ErrMslAssociationSetMappingHasQueryView);
                        watermarkInfo = new TreeGridDesignerWatermarkInfo(errorMessage);
                        return(false);
                    }

                    // make sure that we fully resolve
                    var errorMsg = string.Empty;
                    if (EnsureResolvedStatus(asm, ref errorMsg) == false)
                    {
                        var errorMessage = String.Format(CultureInfo.CurrentCulture, Resources.MappingDetails_ErrMslGeneral, errorMsg);
                        watermarkInfo = new TreeGridDesignerWatermarkInfo(errorMessage);
                        return(false);
                    }

                    // ensure that we don't have any C-side conditions
                    foreach (var cond in asm.Conditions())
                    {
                        if (cond.Name.RefName != null)
                        {
                            var errorMessage = String.Format(
                                CultureInfo.CurrentCulture, Resources.MappingDetails_ErrMslGeneral,
                                Resources.MappingDetails_ErrMslUnsupportedCondition);
                            watermarkInfo = new TreeGridDesignerWatermarkInfo(errorMessage);
                            return(false);
                        }
                    }
                }
            }

            foreach (var associationEnd in association.AssociationEnds())
            {
                string duplicatePropertyName;
                var    entityType = associationEnd.Type.Target;
                if (!CheckDuplicateEntityProperty(entityType, out duplicatePropertyName))
                {
                    var errorMessage = String.Format(
                        CultureInfo.CurrentCulture, Resources.MappingDetails_ErrDuplicatePropertyNameForAssociationEndEntity,
                        entityType.LocalName.Value, duplicatePropertyName);
                    errorMessage  = String.Format(CultureInfo.CurrentCulture, Resources.MappingDetails_ErrMslGeneral, errorMessage);
                    watermarkInfo = new TreeGridDesignerWatermarkInfo(errorMessage);
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 15
0
            internal void CheckForUnmappedAssociation(Association a)
            {
                if (a.RuntimeModelRoot() is ConceptualEntityModel)
                {
                    var severity = ValidationHelper.IsStorageModelEmpty(a.Artifact) ? ErrorInfo.Severity.WARNING : ErrorInfo.Severity.ERROR;
                    var asms     = a.GetAntiDependenciesOfType <AssociationSetMapping>();
                    if (asms.Count == 0)
                    {
                        if (a.ReferentialConstraint != null &&
                            EdmFeatureManager.GetForeignKeysInModelFeatureState(a.Artifact.SchemaVersion).IsEnabled())
                        {
                            // no ASM, but we have a ref constraint.
                            return;
                        }
                        // check whether Association is mapped using QueryView
                        if (null != a.AssociationSet)
                        {
                            asms = a.AssociationSet.GetAntiDependenciesOfType <AssociationSetMapping>();
                            foreach (var asm in asms)
                            {
                                if (asm.HasQueryViewElement)
                                {
                                    return;
                                }
                            }
                        }

                        var msg = String.Format(
                            CultureInfo.CurrentCulture, Resources.EscherValidation_UnmappedAssociation, a.LocalName.Value);
                        ArtifactSet.AddError(
                            new ErrorInfo(severity, msg, a, ErrorCodes.ESCHER_VALIDATOR_UNMAPPED_ASSOCIATION, ErrorClass.Escher_MSL));
                        return;
                    }

                    // association is mapped, so check for unmapped association ends
                    foreach (var ae in a.AssociationEnds())
                    {
                        var ases = ae.GetAntiDependenciesOfType <AssociationSetEnd>();
                        foreach (var ase in ases)
                        {
                            var eps = ase.GetAntiDependenciesOfType <EndProperty>();
                            if (eps.Count == 0)
                            {
                                // Association end is not mapped.  Find nav prop to locate the error
                                EFObject objectForError = null;

                                foreach (var np in ae.GetAntiDependenciesOfType <NavigationProperty>())
                                {
                                    objectForError = np;
                                    break;
                                }

                                if (objectForError == null)
                                {
                                    objectForError = a;
                                }

                                var msg = String.Format(
                                    CultureInfo.CurrentCulture, Resources.EscherValidation_UnmappedAssociationEnd,
                                    ae.GetNameAttribute().Value);
                                ArtifactSet.AddError(
                                    new ErrorInfo(
                                        severity, msg, objectForError, ErrorCodes.ESCHER_VALIDATOR_UNMAPPED_ASSOCIATION_END,
                                        ErrorClass.Escher_MSL));
                            }
                        }
                    }
                }
            }
        public static void AddSchemaSpecificReplacements(IDictionary <string, string> replacementsDictionary, Version schemaVersion)
        {
            Debug.Assert(replacementsDictionary != null, "replacementsDictionary is null.");
            Debug.Assert(schemaVersion != null, "schemaVersion is null.");
            Debug.Assert(!replacementsDictionary.ContainsKey("$edmxversion$"), "replacementsDictionary contains key '$edmxversion$'");
            Debug.Assert(
                !replacementsDictionary.ContainsKey("$edmxnamespacename$"), "replacementsDictionary contains key '$edmxnamespacename$'");
            Debug.Assert(
                !replacementsDictionary.ContainsKey("$ssdlnamespacename$"), "replacementsDictionary contains key '$ssdlnamespacename$'");
            Debug.Assert(
                !replacementsDictionary.ContainsKey("$csdlnamespacename$"), "replacementsDictionary contains key '$csdlnamespacename$'");
            Debug.Assert(
                !replacementsDictionary.ContainsKey("$msdlnamespacename$"), "replacementsDictionary contains key '$msdlnamespacename$'");
            Debug.Assert(
                !replacementsDictionary.ContainsKey("$essgnamespacename$"), "replacementsDictionary contains key '$essgnamespacename$'");
            Debug.Assert(
                !replacementsDictionary.ContainsKey("$cgnamespacename$"), "replacementsDictionary contains key '$cgnamespacename$'");
            Debug.Assert(
                !replacementsDictionary.ContainsKey("$annotationnamespace$"), "replacementsDictionary contains key '$annotationnamespace$'");
            Debug.Assert(
                !replacementsDictionary.ContainsKey("$lazyloadingattribute$"),
                "replacementsDictionary contains key '$lazyloadingattribute$'");
            Debug.Assert(
                !replacementsDictionary.ContainsKey("$useStrongSpatialTypesAttribute$"),
                "replacementsDictionary contains key '$useStrongSpatialTypesAttribute$'");

            // Set the namespace names (EDMX, CodeGen, ESSG, CSDL, MSDL, and SSDL)
            replacementsDictionary.Add("$edmxversion$", schemaVersion.ToString(2)); // only print Major.Minor version information
            replacementsDictionary.Add("$edmxnamespacename$", SchemaManager.GetEDMXNamespaceName(schemaVersion));
            replacementsDictionary.Add("$ssdlnamespacename$", SchemaManager.GetSSDLNamespaceName(schemaVersion));
            replacementsDictionary.Add("$csdlnamespacename$", SchemaManager.GetCSDLNamespaceName(schemaVersion));
            replacementsDictionary.Add("$msdlnamespacename$", SchemaManager.GetMSLNamespaceName(schemaVersion));
            replacementsDictionary.Add(
                "$essgnamespacename$",
                SchemaManager.GetEntityStoreSchemaGeneratorNamespaceName());
            replacementsDictionary.Add(
                "$cgnamespacename$",
                SchemaManager.GetCodeGenerationNamespaceName());

            if (EdmFeatureManager.GetLazyLoadingFeatureState(schemaVersion).IsEnabled() ||
                EdmFeatureManager.GetUseStrongSpatialTypesFeatureState(schemaVersion).IsEnabled())
            {
                replacementsDictionary.Add(
                    "$annotationnamespace$",
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "xmlns:annotation=\"{0}\"",
                        SchemaManager.GetAnnotationNamespaceName()));
            }
            else
            {
                replacementsDictionary.Add("$annotationnamespace$", string.Empty);
            }

            if (EdmFeatureManager.GetLazyLoadingFeatureState(schemaVersion).IsEnabled())
            {
                replacementsDictionary.Add("$lazyloadingattribute$", "annotation:LazyLoadingEnabled=\"true\"");
            }
            else
            {
                replacementsDictionary.Add("$lazyloadingattribute$", string.Empty);
            }

            // set UseStrongSpatialTypes to false as runtime will throw exception if true (as of V3 - to be updated in later version of runtime)
            if (EdmFeatureManager.GetUseStrongSpatialTypesFeatureState(schemaVersion).IsEnabled())
            {
                replacementsDictionary.Add(
                    "$useStrongSpatialTypesAttribute$",
                    "annotation:UseStrongSpatialTypes=\"false\"");
            }
            else
            {
                replacementsDictionary.Add("$useStrongSpatialTypesAttribute$", string.Empty);
            }
        }
Esempio n. 17
0
        public void Invoke()
        {
            Debug.Assert(_association != null, "The Association reference is null");

            // if the association was deleted in this transaction, just return since we won't need to process it
            if (_association == null ||
                _association.XObject == null)
            {
                return;
            }

            // if foreign keys are supported in this EF version, then we skip all processing here.
            if (EdmFeatureManager.GetForeignKeysInModelFeatureState(_association.Artifact.SchemaVersion).IsEnabled())
            {
                return;
            }

            Debug.Assert(_association.EntityModel.IsCSDL, "Inferring ref constraints isn't valid for SSDL associations");
            Debug.Assert(
                _association.AssociationEnds().Count == 2,
                "The association to be processed does not have 2 ends while trying to infer ref constraints");
            Debug.Assert(
                _association.AssociationSet != null,
                "The association being processed does not have a valid AssociationSet while trying to infer ref constraints");

            // some local aliases for readability
            var end1 = _association.AssociationEnds()[0];
            var end2 = _association.AssociationEnds()[1];

            Debug.Assert(end1 != null && end2 != null, "Null end found while trying to infer ref constraints");
            if (end1 == null ||
                end2 == null)
            {
                return;
            }

            // regardless, we will remove the constraint
            if (_association.ReferentialConstraint != null)
            {
                DeleteEFElementCommand.DeleteInTransaction(_context, _association.ReferentialConstraint);
            }

            // we will never create a constraint against a self-association
            if (end1.Type.Target == end2.Type.Target)
            {
                return;
            }

            AssociationEnd principal = null;
            AssociationEnd dependent = null;

            ModelHelper.DeterminePrincipalDependentAssociationEnds(
                _association, out principal, out dependent,
                ModelHelper.DeterminePrincipalDependentAssociationEndsScenario.InferReferentialConstraint);

            // We found our principal and dependent ends but we still need to confirm that
            // the AssociationSetMapping contains key properties that are mapped to the same column
            if (principal != null &&
                principal.Type.Target != null &&
                dependent != null &&
                dependent.Type.Target != null)
            {
                var associationSet = _association.AssociationSet;
                if (associationSet != null)
                {
                    var asm = associationSet.AssociationSetMapping;
                    if (asm != null &&
                        asm.EndProperties().Count == 2)
                    {
                        // any commonly mapped properties will be loaded into these HashSets
                        var principalPropertyRefs = new HashSet <Property>();
                        var dependentPropertyRefs = new HashSet <Property>();

                        EndProperty dependentEndProperty = null;
                        EndProperty principalEndProperty = null;
                        var         endProp1             = asm.EndProperties()[0];
                        var         endProp2             = asm.EndProperties()[1];
                        if (endProp1.Name.Target != null)
                        {
                            if (endProp1.Name.Target.Role.Target == dependent)
                            {
                                dependentEndProperty = endProp1;
                                principalEndProperty = endProp2;
                            }
                            else
                            {
                                dependentEndProperty = endProp2;
                                principalEndProperty = endProp1;
                            }
                        }

                        Debug.Assert(
                            dependentEndProperty != null && principalEndProperty != null,
                            "Either dependent or principal EndProperty is null");
                        if (dependentEndProperty != null &&
                            principalEndProperty != null)
                        {
                            // for each column that is mapped to a key property on the dependent end, determine if there is a
                            // key property on the principal end that it is also mapped to. If there is, then we need a
                            // ReferentialConstraint
                            foreach (var dependentScalarProp in dependentEndProperty.ScalarProperties())
                            {
                                var principalScalarProp =
                                    principalEndProperty.ScalarProperties()
                                    .FirstOrDefault(psp => psp.ColumnName.Target == dependentScalarProp.ColumnName.Target);
                                if (principalScalarProp != null)
                                {
                                    principalPropertyRefs.Add(principalScalarProp.Name.Target);
                                    dependentPropertyRefs.Add(dependentScalarProp.Name.Target);
                                }
                            }

                            Debug.Assert(
                                principalPropertyRefs.Count == dependentPropertyRefs.Count,
                                "List of keys are mismatched while trying to create a Ref Constraint");
                            if (principalPropertyRefs.Count > 0 &&
                                dependentPropertyRefs.Count > 0 &&
                                principalPropertyRefs.Count == dependentPropertyRefs.Count)
                            {
                                // if the propertyRefs sets have any data in them, add the constraint
                                var cmd = new CreateReferentialConstraintCommand(
                                    principal, dependent, principalPropertyRefs, dependentPropertyRefs);
                                CommandProcessor.InvokeSingleCommand(_context, cmd);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 18
0
 internal bool IsReadOnlyLazyLoadingEnabled()
 {
     return(!EdmFeatureManager.GetLazyLoadingFeatureState(TypedEFElement.Artifact.SchemaVersion).IsEnabled());
 }
Esempio n. 19
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.Key == Key.F1)
            {
                // do not respond to F1 Help
                e.Handled = true;
                return;
            }

            if (e.Key == Key.Insert)
            {
                var selected = GetSelectedExplorerEFElement();
                var context  = new EfiTransactionContext();
                if (selected is ExplorerComplexTypes)
                {
                    var cpc = new CommandProcessorContext(
                        Context, EfiTransactionOriginator.ExplorerWindowOriginatorId,
                        Design.Resources.Tx_AddComplexType, null, context);
                    var complexType = CreateComplexTypeCommand.CreateComplexTypeWithDefaultName(cpc);
                    Debug.Assert(complexType != null, "Creating ComplexType failed");
                    NavigateToElementAndPutInRenameMode(complexType);
                    return;
                }

                var explorerComplexType = selected as ExplorerComplexType;
                if (explorerComplexType != null)
                {
                    var complexType = explorerComplexType.ModelItem as ComplexType;
                    if (complexType != null)
                    {
                        var cpc = new CommandProcessorContext(
                            Context,
                            EfiTransactionOriginator.ExplorerWindowOriginatorId,
                            Design.Resources.Tx_CreateScalarProperty, null, context);
                        var property = CreateComplexTypePropertyCommand.CreateDefaultProperty(
                            cpc, complexType,
                            ModelConstants.DefaultPropertyType);
                        Debug.Assert(property != null, "Creating Property failed");
                        NavigateToElementAndPutInRenameMode(property);
                    }
                    else
                    {
                        Debug.Fail("complexType shouldn't be null");
                    }
                    return;
                }

                // Event handler if the user presses 'Insert' button from the keyboard in the EnumTypes node.
                var explorerEnumTypes = selected as ExplorerEnumTypes;
                if (explorerEnumTypes != null)
                {
                    var entityModel = explorerEnumTypes.Parent.ModelItem as ConceptualEntityModel;
                    if (EdmFeatureManager.GetEnumTypeFeatureState(entityModel.Artifact).IsEnabled())
                    {
                        var cpc = new CommandProcessorContext(
                            Context,
                            EfiTransactionOriginator.ExplorerWindowOriginatorId,
                            Design.Resources.Tx_CreateScalarProperty, null, context);
                        var enumType = CreateEnumTypeCommand.CreateEnumTypeWithDefaultName(cpc);
                        Debug.Assert(enumType != null, "Creating Enum failed");
                        NavigateToElementAndPutInRenameMode(enumType);
                    }
                    return;
                }

                // Event handler if the user presses 'Insert' button from the keyboard in the diagrams node.
                var explorerDiagram = selected as ExplorerDiagrams;
                if (explorerDiagram != null)
                {
                    var diagrams = explorerDiagram.ModelItem as Diagrams;
                    if (diagrams != null)
                    {
                        var cpc = new CommandProcessorContext(
                            Context,
                            EfiTransactionOriginator.ExplorerWindowOriginatorId,
                            Design.Resources.Tx_CreateDiagram, null, context);
                        var diagram = CreateDiagramCommand.CreateDiagramWithDefaultName(cpc);
                        Debug.Assert(diagram != null, "The selected ExplorerEFElementItem is not type of diagram.");
                        NavigateToElementAndPutInRenameMode(diagram);
                        // Automatically open the diagram that we selected in the previous line.
                        var selectedExplorerEFElement = GetSelectedExplorerEFElement();
                        if (selectedExplorerEFElement is ExplorerDiagram)
                        {
                            ExecuteActivate();
                        }
                        else
                        {
                            Debug.Fail("The selected ExplorerEFElementItem is not type of diagram.");
                        }
                    }
                    else
                    {
                        Debug.Fail("diagram folder shouldn't be null");
                    }
                    return;
                }
            }

            base.OnKeyDown(e);
        }
 internal virtual bool IsReadOnlyTypeAccess()
 {
     return(!EdmFeatureManager.GetEntityContainerTypeAccessFeatureState(TypedEFElement.Artifact.SchemaVersion)
            .IsEnabled());
 }
Esempio n. 21
0
        public void ExecuteActivate()
        {
            var viewModelHelper = ExplorerViewModelHelper as EntityDesignExplorerViewModelHelper;

            Debug.Assert(viewModelHelper != null, "ExplorerViewModelHelper is null or is not type of EntityDesignExplorerViewModelHelper");

            // Function-Import/Function  double-click behavior.
            var selectedExplorerEFElement  = GetSelectedExplorerEFElement();
            var explorerFunctionImport     = selectedExplorerEFElement as ExplorerFunctionImport;
            var explorerFunction           = selectedExplorerEFElement as ExplorerFunction;
            var explorerDiagram            = selectedExplorerEFElement as ExplorerDiagram;
            var explorerConceptualProperty = selectedExplorerEFElement as ExplorerConceptualProperty;
            var explorerEnumType           = selectedExplorerEFElement as ExplorerEnumType;

            var diagramManagercontextItem = EditingContext.Items.GetValue <DiagramManagerContextItem>();

            Debug.Assert(diagramManagercontextItem != null, "Could not find instance of: DiagramManagerContextItem in editing context.");

            if (viewModelHelper != null &&
                explorerFunctionImport != null)
            {
                viewModelHelper.EditFunctionImport(explorerFunctionImport.ModelItem as FunctionImport);
            }
            // if the user double-clicks on the function in the model browser.
            else if (viewModelHelper != null &&
                     explorerFunction != null)
            {
                var function = explorerFunction.ModelItem as Function;
                Debug.Assert(function != null, "ExplorerFunction.ModelItem value is expected to be typeof Function and not null.");

                if (function != null)
                {
                    var schemaVersion = (function.Artifact == null ? null : function.Artifact.SchemaVersion);
                    if (function.IsComposable != null &&
                        function.IsComposable.Value &&
                        !EdmFeatureManager.GetComposableFunctionImportFeatureState(schemaVersion).IsEnabled())
                    {
                        // Composable Function Import for Version <= V2 - give warning message
                        VsUtils.ShowMessageBox(
                            PackageManager.Package,
                            string.Format(
                                CultureInfo.CurrentCulture, Design.Resources.FunctionImport_CannotCreateFromComposableFunction,
                                EntityFrameworkVersion.Version2),
                            OLEMSGBUTTON.OLEMSGBUTTON_OK,
                            OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                            OLEMSGICON.OLEMSGICON_WARNING);
                    }
                    else
                    {
                        // first we detect whether there are existing FunctionImport(s) with the underlying function.
                        var itemBindings            = function.GetDependentBindings();
                        var matchFunctionImportList = new List <FunctionImport>();
                        foreach (var itemBinding in itemBindings)
                        {
                            var functionImportMapping = itemBinding.GetParentOfType(typeof(FunctionImportMapping)) as FunctionImportMapping;
                            if (functionImportMapping != null &&
                                functionImportMapping.FunctionImportName != null &&
                                functionImportMapping.FunctionImportName.Target != null)
                            {
                                matchFunctionImportList.Add(functionImportMapping.FunctionImportName.Target);
                            }
                        }
                        // if we found function imports for the underlying function, navigate to the first function import in alphabetical sorted list
                        if (matchFunctionImportList.Count > 0)
                        {
                            matchFunctionImportList.Sort(EFElement.EFElementDisplayNameComparison);
                            ExplorerNavigationHelper.NavigateTo(matchFunctionImportList[0]);
                        }
                        else
                        {
                            // We could not find any function import for the underlying function, show new function import dialog
                            viewModelHelper.CreateFunctionImport(explorerFunction.ModelItem as Function);
                        }
                    }
                }
            }
            else if (explorerEnumType != null)
            {
                var enumType = explorerEnumType.ModelItem as EnumType;
                Debug.Assert(enumType != null, "ExplorerEnumType's model item is null or is not type of EnumType.");
                EntityDesignViewModelHelper.EditEnumType(
                    Context, EfiTransactionOriginator.ExplorerWindowOriginatorId, new EnumTypeViewModel(enumType));
            }
            // if the selected Explorer is type of ExplorerDiagram.
            else if (explorerDiagram != null &&
                     diagramManagercontextItem != null)
            {
                diagramManagercontextItem.DiagramManager.OpenDiagram(explorerDiagram.DiagramMoniker, true);
            }
            else if (explorerConceptualProperty != null)
            {
                Debug.Assert(
                    explorerConceptualProperty.Parent is ExplorerConceptualEntityType,
                    "Only properties that belong to Entity type are supported.");
                if (explorerConceptualProperty.Parent is ExplorerConceptualEntityType)
                {
                    diagramManagercontextItem.DiagramManager.ActiveDiagram.AddOrShowEFElementInDiagram(explorerConceptualProperty.ModelItem);
                }
            }
            // if the selected Explorer is type of ExplorerConceptualEntityType, ExplorerConceptualAssociation, ExplorerNavigationProperty, ExplorerAssociationSet or ExplorerEntitySet
            else if (diagramManagercontextItem != null &&
                     diagramManagercontextItem.DiagramManager != null &&
                     diagramManagercontextItem.DiagramManager.ActiveDiagram != null)
            {
                Debug.Assert(
                    selectedExplorerEFElement is ExplorerConceptualEntityType ||
                    selectedExplorerEFElement is ExplorerConceptualAssociation ||
                    selectedExplorerEFElement is ExplorerNavigationProperty ||
                    selectedExplorerEFElement is ExplorerAssociationSet ||
                    selectedExplorerEFElement is ExplorerEntitySet ||
                    selectedExplorerEFElement is ExplorerEntityTypeShape,
                    "The selected explorer type:" + selectedExplorerEFElement.GetType().Name + " is not supported.");

                if (selectedExplorerEFElement is ExplorerConceptualEntityType ||
                    selectedExplorerEFElement is ExplorerConceptualAssociation ||
                    selectedExplorerEFElement is ExplorerNavigationProperty ||
                    selectedExplorerEFElement is ExplorerAssociationSet ||
                    selectedExplorerEFElement is ExplorerEntitySet)
                {
                    diagramManagercontextItem.DiagramManager.ActiveDiagram.AddOrShowEFElementInDiagram(selectedExplorerEFElement.ModelItem);
                }
                else if (selectedExplorerEFElement is ExplorerEntityTypeShape)
                {
                    var entityTypeShape = selectedExplorerEFElement.ModelItem as EntityTypeShape;
                    Debug.Assert(entityTypeShape != null, "ExplorerEntityTypeShape does not contain instance of EntityTypeShape");
                    if (entityTypeShape != null)
                    {
                        diagramManagercontextItem.DiagramManager.OpenDiagram(entityTypeShape.Diagram.Id, true);
                        diagramManagercontextItem.DiagramManager.ActiveDiagram.AddOrShowEFElementInDiagram(
                            entityTypeShape.EntityType.Target);
                    }
                }
            }
        }
 internal virtual bool IsReadOnlyGenerateUpdateViews()
 {
     return(!EdmFeatureManager.GetGenerateUpdateViewsFeatureState(TypedEFElement.Artifact.SchemaVersion)
            .IsEnabled());
 }