internal static NormalizedName NameNormalizer(EFElement parent, string refName) { Debug.Assert(parent != null, "parent should not be null"); NormalizedName normalizedName = null; if (refName == null) { return(null); } var modfunc = parent as ModificationFunction; if (modfunc != null) { normalizedName = EFNormalizableItemDefaults.DefaultNameNormalizerForMSL(modfunc, refName); } else { var parentItem = parent; normalizedName = EFNormalizableItemDefaults.DefaultNameNormalizerForEDM(parentItem, refName); } if (normalizedName == null) { var symbol = new Symbol(refName); normalizedName = new NormalizedName(symbol, null, null, refName); } return(normalizedName); }
internal static NormalizedName NameNormalizer(EFElement parent, string refName) { Debug.Assert(parent != null, "parent should not be null"); NormalizedName normalizedName = null; if (refName == null) { return(null); } var parentEndProperty = parent as EndProperty; if (parentEndProperty != null) { normalizedName = EFNormalizableItemDefaults.DefaultNameNormalizerForMSL(parentEndProperty, refName); } else { var parentItem = parent; normalizedName = EFNormalizableItemDefaults.DefaultNameNormalizerForEDM(parentItem, refName); } if (normalizedName == null) { normalizedName = new NormalizedName(new Symbol(refName), null, null, refName); } return(normalizedName); }
internal static NormalizedName NameNormalizer(EFElement parent, string refName) { Debug.Assert(parent != null, "parent should not be null"); if (refName == null) { return(null); } NormalizedName normalizedName = null; var parentAssociation = parent as Association; var parentAssociationSet = parent as AssociationSet; var parentAssociationSetMapping = parent as AssociationSetMapping; var parentNavigationProperty = parent as NavigationProperty; if (parentAssociation != null) { var model = parentAssociation.Parent as BaseEntityModel; if (model != null) { // we are coming up with the object's name for the first time var symbol = new Symbol(model.NamespaceValue, parentAssociation.LocalName.Value); normalizedName = new NormalizedName(symbol, null, null, parentAssociation.LocalName.Value); } } else if (parentAssociationSet != null) { // we are wanting to resolve a reference from an Association Set that may or may not // use the alias defined in the EntityModel normalizedName = EFNormalizableItemDefaults.DefaultNameNormalizerForEDM(parentAssociationSet, refName); } else if (parentAssociationSetMapping != null) { normalizedName = EFNormalizableItemDefaults.DefaultNameNormalizerForMSL(parentAssociationSetMapping, refName); } else if (parentNavigationProperty != null) { normalizedName = EFNormalizableItemDefaults.DefaultNameNormalizerForEDM(parentNavigationProperty, refName); } if (normalizedName == null) { var symbol = new Symbol(refName); normalizedName = new NormalizedName(symbol, null, null, refName); } return(normalizedName); }
// an example use of an alias in a typename // // <Alias cdm:Key="CNorthwind" cdm:Value="Test.Simple.Model" /> // ... // <EntityTypeMapping cdm:TypeName="CNorthwind.CCategory"> // ... // // we need to resolve CNorthwind.CCategory to Test.Simple.Model.CCategory so we // can look it up in the symbol table internal static NormalizedName NameNormalizer(EFElement parent, string refName) { Debug.Assert(parent != null, "parent should not be null"); if (refName == null) { return(null); } // go get the needed parent objects var parentItem = parent; Debug.Assert(parentItem != null, "parent should not be an EFElement"); refName = refName.Trim(); refName = EntityTypeMapping.StripOffIsTypeOf(refName); return(EFNormalizableItemDefaults.DefaultNameNormalizerForMSL(parentItem, refName)); }
protected override void InvokeInternal(CommandProcessorContext cpc) { // get unique name for the property var propertyName = ModelHelper.GetUniqueName(typeof(ConceptualProperty), _parentComplexType, _clipboardProperty.PropertyName); if (!_clipboardProperty.IsComplexProperty) { // scalar property case var cmd = new CreateComplexTypePropertyCommand( propertyName, _parentComplexType, _clipboardProperty.PropertyType, _clipboardProperty.IsNullable); CommandProcessor.InvokeSingleCommand(cpc, cmd); _createdProperty = cmd.Property; } else { // complex property case // first try to find ComplexType by it's name var complexTypeNormalizedName = EFNormalizableItemDefaults.DefaultNameNormalizerForEDM( _parentComplexType, _clipboardProperty.PropertyType); var items = _parentComplexType.Artifact.ArtifactSet.GetSymbolList(complexTypeNormalizedName.Symbol); ComplexType complexType = null; foreach (var efElement in items) { // the GetSymbolList() method might return more than one element so choose the first ComplexType complexType = efElement as ComplexType; if (complexType != null) { break; } } if (complexType != null) { // if the ComplexType is found, simply use the create command var cmd = new CreateComplexTypePropertyCommand(propertyName, _parentComplexType, complexType, false); CommandProcessor.InvokeSingleCommand(cpc, cmd); _createdProperty = cmd.Property; } else { // in this case we're going to create ComplexProperty with unresolved type var complexProperty = new ComplexConceptualProperty(_parentComplexType, null); complexProperty.ComplexType.SetXAttributeValue(_clipboardProperty.PropertyType); // set the name and add to the parent entity complexProperty.LocalName.Value = propertyName; _parentComplexType.AddProperty(complexProperty); // set other attributes of the property complexProperty.Nullable.Value = BoolOrNone.FalseValue; XmlModelHelper.NormalizeAndResolve(complexProperty); Debug.Assert( complexProperty.ComplexType.Status != BindingStatus.Known, "Why didn't we find the ComplexType in the ArtifactSet previously?"); _createdProperty = complexProperty; } } // safety check Debug.Assert(_createdProperty != null, "We didn't get good Property out of the command"); if (_createdProperty != null) { // set Property attributes var cmd2 = new SetConceptualPropertyFacetsCommand( _createdProperty, _clipboardProperty.Default, _clipboardProperty.ConcurrencyMode, _clipboardProperty.GetterAccessModifier, _clipboardProperty.SetterAccessModifier, _clipboardProperty.MaxLength, DefaultableValueBoolOrNone.GetFromNullableBool(_clipboardProperty.FixedLength), _clipboardProperty.Precision, _clipboardProperty.Scale, DefaultableValueBoolOrNone.GetFromNullableBool(_clipboardProperty.Unicode), _clipboardProperty.Collation); CommandProcessor.InvokeSingleCommand(cpc, cmd2); } }
protected override void InvokeInternal(CommandProcessorContext cpc) { // safety check, this should never be hit Debug.Assert(EntityType != null, "InvokeInternal is called when EntityType is null."); if (EntityType == null) { throw new InvalidOperationException("InvokeInternal is called when EntityType is null"); } // check for uniqueness string msg; if (!ModelHelper.ValidateEntityPropertyName(EntityType, Name, true, out msg)) { throw new CommandValidationFailedException(msg); } // create the property _createdProperty = new ComplexConceptualProperty(EntityType, null, _insertPosition); // set the name and add to the parent entity _createdProperty.LocalName.Value = Name; if (ComplexType != null) { _createdProperty.ComplexType.SetRefName(ComplexType); } else if (!String.IsNullOrEmpty(_typeName)) { // separate this name into the namespace and name parts string typeNamespace; string typeLocalName; EFNormalizableItemDefaults.SeparateRefNameIntoParts(_typeName, out typeNamespace, out typeLocalName); // look to see if the referenced complex type exists (it may not if they are pasting across models) // just search on local name since two models will have different namespaces probably ComplexType type = null; var cem = EntityType.EntityModel as ConceptualEntityModel; foreach (var c in cem.ComplexTypes()) { if (string.Compare(typeLocalName, c.LocalName.Value, StringComparison.CurrentCultureIgnoreCase) == 0) { type = c; break; } } // set the complex type reference if (type == null) { // if we didn't find the complex type locally, write out the type name - but for the local namespace // this will let the user subsequently copy the complex type and this property will start working again var typeSymbol = new Symbol(cem.Namespace.Value, typeLocalName); _createdProperty.ComplexType.SetXAttributeValue(typeSymbol.ToDisplayString()); } else { _createdProperty.ComplexType.SetRefName(type); } } else { _createdProperty.ComplexType.SetXAttributeValue(Resources.ComplexPropertyUndefinedType); } // runtime does not support nullable complex properties, need to set it to false since the default is true _createdProperty.Nullable.Value = BoolOrNone.FalseValue; EntityType.AddProperty(_createdProperty); XmlModelHelper.NormalizeAndResolve(_createdProperty); }
internal static NormalizedName FunctionNameNormalizer(EFElement parent, string refName) { return(EFNormalizableItemDefaults.DefaultNameNormalizerForMSL(parent, refName)); }