src/Misc/EFTools/EntityDesign/UI/ViewModels/MappingDetails/Association/MappingEndScalarProperty.cs
// <summary>
//     The mapping view model contains a MappingEndScalarProperty for every key in each end.  The user can clear out the
//     underlying scalar property, but that doesn't remove or add the MappingEndScalarProperty.  We need the placeholder
//     in the view model to show the nodes in the Trid even if there isn't a mapping.  Thus, we don't need to call
//     this.Parent.AddChild(this) since its already there.
// </summary>
The mapping view model contains a MappingEndScalarProperty for every key in each end.  The user can clear out the
underlying scalar property, but that doesn't remove or add the MappingEndScalarProperty.  We need the placeholder
in the view model to show the nodes in the Trid even if there isn't a mapping.  Thus, we don't need to call
this.Parent.AddChild(this) since its already there.
The mapping view model contains a MappingEndScalarProperty for every key in each end . The user can clear out the underlying scalar property but that doesn ' t remove or add the MappingEndScalarProperty . We need the placeholder in the view model to show the nodes in the Trid even if there isn ' t a mapping . Thus we don ' t need to call this . Parent . AddChild ( this ) since its already there .
internal override void CreateModelItem(CommandProcessorContext cpc, EditingContext context, EFElement underlyingModelItem)
        {
            Debug.Assert(underlyingModelItem != null, "The underlyingModelItem cannot be null");
            var tableColumn = underlyingModelItem as Property;
            Debug.Assert(context != null, "The context argument cannot be null");
            Debug.Assert(ScalarProperty == null, "Don't call this method if we already have a ModelItem");
            Debug.Assert(tableColumn != null, "The tableColumn cannot be null.");
            if (tableColumn == null)
            {
                return;
            }
            Debug.Assert(tableColumn.EntityType.EntityModel.IsCSDL == false, "tableColumn must be a Store-side Property");
            Context = context;
            var entityProperty = MappingAssociationSetEnd.ConceptualEntityType.GetFirstNamedChildByLocalName(Property) as Property;
            if (entityProperty == null)
            {
                EntityType topMostBaseType = MappingAssociationSetEnd.ConceptualEntityType.ResolvableTopMostBaseType;
                entityProperty = topMostBaseType.GetFirstNamedChildByLocalName(Property) as Property;
            }
            Debug.Assert(entityProperty != null, "Failed looking up entity property for ScalarProperty.");
            if (entityProperty == null)
            {
                return;
            }
            if (cpc == null)
            {
                cpc = new CommandProcessorContext(
                    Context, EfiTransactionOriginator.MappingDetailsOriginatorId, Resources.Tx_CreateScalarProperty);
            }
            CreateEndScalarPropertyCommand cmd = null;
            var end = MappingAssociationSetEnd.AssociationSetEnd.EndProperty;
            if (end == null)
            {
                cmd = new CreateEndScalarPropertyCommand(
                    MappingAssociationSet.AssociationSet.AssociationSetMapping, MappingAssociationSetEnd.AssociationSetEnd, entityProperty,
                    tableColumn);
            }
            else
            {
                cmd = new CreateEndScalarPropertyCommand(end, entityProperty, tableColumn);
            }
            cmd.PostInvokeEvent += (o, eventArgs) =>
                {
                    var sp = cmd.ScalarProperty;
                    Debug.Assert(sp != null, "cmd failed to generate ScalarProperty");
                    ModelItem = sp;
                };
            try
            {
                var cp = new CommandProcessor(cpc, cmd);
                cp.Invoke();
            }
            catch
            {
                ModelItem = null;
                throw;
            }
        }
internal override void CreateModelItem ( CommandProcessorContext cpc , EditingContext context , EFElement underlyingModelItem ) { Debug . Assert ( underlyingModelItem != null , " " ) ; var tableColumn = underlyingModelItem as Property ; Debug . Assert ( context != null , " " ) ; Debug . Assert ( ScalarProperty == null , " " ) ; Debug . Assert ( tableColumn != null , " " ) ; if ( tableColumn == null ) { return ; } Debug . Assert ( tableColumn . EntityType . EntityModel . IsCSDL == false , " " ) ; Context = context ; var entityProperty = MappingAssociationSetEnd . ConceptualEntityType . GetFirstNamedChildByLocalName ( Property ) as Property ; if ( entityProperty == null ) { EntityType topMostBaseType = MappingAssociationSetEnd . ConceptualEntityType . ResolvableTopMostBaseType ; entityProperty = topMostBaseType . GetFirstNamedChildByLocalName ( Property ) as Property ; } Debug . Assert ( entityProperty != null , " " ) ; if ( entityProperty == null ) { return ; } if ( cpc == null ) { cpc = new CommandProcessorContext ( Context , EfiTransactionOriginator . MappingDetailsOriginatorId , Resources . Tx_CreateScalarProperty ) ; } CreateEndScalarPropertyCommand cmd = null ; var end = MappingAssociationSetEnd . AssociationSetEnd . EndProperty ; if ( end == null ) { cmd = new CreateEndScalarPropertyCommand ( MappingAssociationSet . AssociationSet . AssociationSetMapping , MappingAssociationSetEnd . AssociationSetEnd , entityProperty , tableColumn ) ; } else { cmd = new CreateEndScalarPropertyCommand ( end , entityProperty , tableColumn ) ; } cmd . PostInvokeEvent += ( o , eventArgs ) => { var sp = cmd . ScalarProperty ; Debug . Assert ( sp != null , " " ) ; ModelItem = sp ; } ; try { var cp = new CommandProcessor ( cpc , cmd ) ; cp . Invoke ( ) ; } catch { ModelItem = null ; throw ; } }
The mapping view model contains a MappingEndScalarProperty for every key in each end.
The mapping view model contains a MappingEndScalarProperty for every key in each end .
// find the c-side property based on the passed in name // they might be trying to map a key from the base class // create our context if we don't have one // create the right command // we don't have an end yet, this version will create an end as well as the scalar property // set up our post event to fix up the view model // fix up our view model (we don't have to add this to the parent's children collection // because we created a placeholder row already for every key in the entity) // now make the change
cpc
CommandProcessorContext
context
EditingContext
underlyingModelItem
EFElement