private static Property CreateStorageProperty(StorageEntityType parentEntity, string name, string type) { var property = new StorageProperty(parentEntity, null); property.LocalName.Value = name; property.Type.Value = type; return(property); }
internal AssociationSetEndMappingBuilder(AssociationSetEnd setEnd, StorageEntityType storageEntityType) { Debug.Assert(setEnd != null, "setEnd should not be null"); Debug.Assert(storageEntityType != null, "storageEntityType should not be null"); _setEnd = setEnd; _storageEntityType = storageEntityType; }
protected override void InvokeInternal(CommandProcessorContext cpc) { var service = cpc.EditingContext.GetEFArtifactService(); var artifact = service.Artifact; // the model that we want to add the entity to var model = ModelHelper.GetEntityModel(artifact, ModelSpaceValue); if (model == null) { throw new CannotLocateParentItemException(); } // check for uniqueness if (UniquifyName) { Name = ModelHelper.GetUniqueName(typeof(EntityType), model, Name); } else { string msg = null; if (ModelHelper.IsUniqueName(typeof(EntityType), model, Name, false, out msg) == false) { throw new CommandValidationFailedException(msg); } } // create the new item in our model EntityType entity = null; if (model.IsCSDL) { entity = new ConceptualEntityType(model as ConceptualEntityModel, null); } else { entity = new StorageEntityType(model as StorageEntityModel, null); } Debug.Assert(entity != null, "entity should not be null"); if (entity == null) { throw new ItemCreationFailureException(); } // set the name, add it to the parent item entity.LocalName.Value = Name; model.AddEntityType(entity); XmlModelHelper.NormalizeAndResolve(entity); CreatedEntityType = entity; }
/// <summary> /// Creates a new property in the passed in storage entity and optionally sets additional /// facets on the property. /// NOTE: If the cpc already has an active transaction, these changes will be in that transaction /// and the caller of this helper method must commit it to see these changes commited. /// </summary> /// <param name="cpc"></param> /// <param name="name">The name of the property</param> /// <param name="entityType">Must be a storage entity</param> /// <param name="type">The type to use for this property (cannot be empty)</param> /// <param name="nullable">Flag whether the property is nullable or not</param> /// <param name="theDefault">Optional: the default value for this property</param> /// <param name="maxLength">Optional facet</param> /// <param name="fixedLength">Optional facet</param> /// <param name="precision">Optional facet</param> /// <param name="scale">Optional facet</param> /// <param name="unicode">Optional facet</param> /// <param name="collation">Optional facet</param> /// <param name="concurrencyMode">Optional: the concurrency mode for this property</param> /// <returns>The new Property</returns> internal static Property CreateStorageProperty( CommandProcessorContext cpc, string name, StorageEntityType entityType, string type, bool?nullable, StringOrNone theDefault, StringOrPrimitive <UInt32> maxLength, BoolOrNone fixedLength, StringOrPrimitive <UInt32> precision, StringOrPrimitive <UInt32> scale, BoolOrNone unicode, StringOrNone collation, string concurrencyMode) { CommandValidation.ValidateStorageEntityType(entityType); var cpcd = new CreatePropertyCommand(name, entityType, type, nullable); var ssp = new SetPropertyFacetsCommand( cpcd, theDefault, maxLength, fixedLength, precision, scale, unicode, collation, concurrencyMode); var cp = new CommandProcessor(cpc, cpcd, ssp); cp.Invoke(); return(cpcd.CreatedProperty); }
protected override void BuildNew(CommandProcessorContext cpc, string propertyName, string propertyType) { if (StorageEntityType == null || ConceptualEntityType == null) { Debug.Fail("The AssociationSetEndMappingBuilder does not have references to everything it needs"); return; } // try to find the column with this name var tableColumn = StorageEntityType.GetFirstNamedChildByLocalName(propertyName, true) as Property; if (tableColumn != null) { // now see if there is also a property with this name var entityProperty = ConceptualEntityType.GetFirstNamedChildByLocalName(propertyName) as Property; if (entityProperty == null) { // they might be trying to map a key from the base class EntityType topMostBaseType = ConceptualEntityType.ResolvableTopMostBaseType; entityProperty = topMostBaseType.GetFirstNamedChildByLocalName(propertyName) as Property; } // if we have both, create a mapping if (entityProperty != null) { CreateEndScalarPropertyCommand cmd = null; var end = AssociationSetEnd.EndProperty; if (end == null) { // we don't have an end yet, this version will create an end as well as the scalar property cmd = new CreateEndScalarPropertyCommand( AssociationSet.AssociationSetMapping, AssociationSetEnd, entityProperty, tableColumn); } else { cmd = new CreateEndScalarPropertyCommand(end, entityProperty, tableColumn); } CommandProcessor.InvokeSingleCommand(cpc, cmd); } } }
/// <summary> /// A helper method that creates the AssociationSetMapping and also tries to "Intelli-Match" some mappings, that is, if there are /// columns and properties that match by name, we create mappings for the user. /// </summary> /// <param name="cpc"></param> /// <param name="association"></param> /// <param name="storageEntityType"></param> /// <returns></returns> internal static AssociationSetMapping CreateAssociationSetMappingAndIntellimatch( CommandProcessorContext cpc, Association association, StorageEntityType storageEntityType) { var associationSet = association.AssociationSet; Debug.Assert(associationSet != null, "An association found that doesn't have an association set"); var cmd = new CreateAssociationSetMappingCommand(association, storageEntityType); CommandProcessor.InvokeSingleCommand(cpc, cmd); foreach (var setEnd in associationSet.AssociationSetEnds()) { var builder = new AssociationSetEndMappingBuilderForCommand(setEnd, storageEntityType); builder.Build(cpc); } return(cmd.AssociationSetMapping); }
internal AssociationSetEndMappingBuilderForViewModel( AssociationSetEnd setEnd, StorageEntityType storeEntityType, MappingAssociationSetEnd mase) : base(setEnd, storeEntityType) { _mase = mase; }
// <summary> // NOTE: We don't call this.Parent.RemoveChild(this) because this is always called from the MappingEFElement.Delete() method // which will remove this item from the parent. // </summary> internal override void DeleteModelItem(CommandProcessorContext cpc) { Debug.Assert(ModelItem != null, "We are trying to delete a null ModelItem"); if (IsModelItemDeleted() == false) { // create a context if we weren't passed one if (cpc == null) { cpc = new CommandProcessorContext( Context, EfiTransactionOriginator.MappingDetailsOriginatorId, Resources.Tx_DeleteMappingFragment); } var fragment = ModelHelper.FindMappingFragment( cpc, MappingConceptualEntityType.ConceptualEntityType, StorageEntityType, false); Debug.Assert(fragment != null, "could not find MappingFragment for StorageEntityType " + StorageEntityType.ToPrettyString()); if (fragment != null) { // use the item's delete command var deleteCommand = fragment.GetDeleteCommand(); deleteCommand.PostInvokeEvent += (o, eventsArgs) => { ModelItem = null; ColumnMappings.ModelItem = null; }; DeleteEFElementCommand.DeleteInTransaction(cpc, deleteCommand); } } // if IsModelItemDeleted == true, just make sure that it is null anyways ModelItem = null; ColumnMappings.ModelItem = null; }
internal AssociationSetEndMappingBuilderForCommand(AssociationSetEnd setEnd, StorageEntityType storeEntityType) : base(setEnd, storeEntityType) { }