src/Misc/EFTools/EntityDesign/UI/ViewModels/MappingDetails/Table/MappingStorageEntityType.cs
// <summary>
//     When a new table is mapped, we also set up the MappingColumnMappings view model item.  This is a placeholder that
//     contains the scalar property mappings.  It is separated from the other "children", the conditions, simply because of
//     UI requirements that Conditions be UI peers of a "Column Mappings" node in the Trid.
// </summary>
When a new table is mapped, we also set up the MappingColumnMappings view model item.  This is a placeholder that
contains the scalar property mappings.  It is separated from the other "children", the conditions, simply because of
UI requirements that Conditions be UI peers of a "Column Mappings" node in the Trid.
When a new table is mapped we also set up the MappingColumnMappings view model item . This is a placeholder that contains the scalar property mappings . It is separated from the other " children " the conditions simply because of UI requirements that Conditions be UI peers of a " Column Mappings " node in the Trid .
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
        internal override void CreateModelItem(CommandProcessorContext cpc, EditingContext context, EFElement underlyingModelItem)
        {
            Debug.Assert(context != null, "The context argument cannot be null");
            Debug.Assert(StorageEntityType == null, "Don't call this method if we already have a ModelItem");
            Debug.Assert(MappingConceptualEntityType.ConceptualEntityType != null, "The parent item isn't set up correctly");
            Debug.Assert(underlyingModelItem != null, "The underlyingModelItem cannot be null");
            var storeEntityType = underlyingModelItem as EntityType;
            Debug.Assert(
                storeEntityType != null,
                "underlyingModelItem must be of type EntityType, actual type = " + underlyingModelItem.GetType().FullName);
            Debug.Assert(storeEntityType.EntityModel.IsCSDL == false, "The storageEntityType must not be a CSDL EntityType");
            Context = context;
            ColumnMappings.Context = context;
            if (cpc == null)
            {
                cpc = new CommandProcessorContext(
                    Context, EfiTransactionOriginator.MappingDetailsOriginatorId, Resources.Tx_CreateMappingFragment);
            }
            var cet = MappingConceptualEntityType.ConceptualEntityType;
            var defaultEtm = ModelHelper.FindEntityTypeMapping(cpc, cet, EntityTypeMappingKind.Default, false);
            var etmKind = (defaultEtm == null ? EntityTypeMappingKind.IsTypeOf : EntityTypeMappingKind.Default);
            var cmd = new CreateMappingFragmentCommand(cet, storeEntityType, etmKind);
            cmd.PostInvokeEvent += (o, eventsArgs) =>
                {
                    ModelItem = storeEntityType;
                    Parent.AddChild(this);
                    ColumnMappings.ModelItem = storeEntityType;
                    var mappingStrategy = ModelHelper.DetermineCurrentInheritanceStrategy(cet);
                    var topMostBaseType = cet.ResolvableTopMostBaseType;
                    foreach (var child in ColumnMappings.Children)
                    {
                        var msp = child as MappingScalarProperty;
                        if (msp != null)
                        {
                            List<Property> properties;
                            if (ModelHelper.FindScalarPropertyPathByLocalName(cet, msp.ColumnName, out properties))
                            {
                                msp.CreateModelItem(cpc, _context, properties);
                            }
                            else if (InheritanceMappingStrategy.TablePerType == mappingStrategy
                                     &&
                                     ModelHelper.FindScalarPropertyPathByLocalName(topMostBaseType, msp.ColumnName, out properties))
                            {
                                msp.CreateModelItem(cpc, _context, properties);
                            }
                        }
                    }
                };
            try
            {
                var cp = new CommandProcessor(cpc);
                cp.EnqueueCommand(cmd);
                cp.Invoke();
            }
            catch
            {
                ModelItem = null;
                ColumnMappings.ModelItem = null;
                Parent.RemoveChild(this);
                throw;
            }
        }
[ SuppressMessage ( " " , " " ) ] internal override void CreateModelItem ( CommandProcessorContext cpc , EditingContext context , EFElement underlyingModelItem ) { Debug . Assert ( context != null , " " ) ; Debug . Assert ( StorageEntityType == null , " " ) ; Debug . Assert ( MappingConceptualEntityType . ConceptualEntityType != null , " " ) ; Debug . Assert ( underlyingModelItem != null , " " ) ; var storeEntityType = underlyingModelItem as EntityType ; Debug . Assert ( storeEntityType != null , " " + underlyingModelItem . GetType ( ) . FullName ) ; Debug . Assert ( storeEntityType . EntityModel . IsCSDL == false , " " ) ; Context = context ; ColumnMappings . Context = context ; if ( cpc == null ) { cpc = new CommandProcessorContext ( Context , EfiTransactionOriginator . MappingDetailsOriginatorId , Resources . Tx_CreateMappingFragment ) ; } var cet = MappingConceptualEntityType . ConceptualEntityType ; var defaultEtm = ModelHelper . FindEntityTypeMapping ( cpc , cet , EntityTypeMappingKind . Default , false ) ; var etmKind = ( defaultEtm == null ? EntityTypeMappingKind . IsTypeOf : EntityTypeMappingKind . Default ) ; var cmd = new CreateMappingFragmentCommand ( cet , storeEntityType , etmKind ) ; cmd . PostInvokeEvent += ( o , eventsArgs ) => { ModelItem = storeEntityType ; Parent . AddChild ( this ) ; ColumnMappings . ModelItem = storeEntityType ; var mappingStrategy = ModelHelper . DetermineCurrentInheritanceStrategy ( cet ) ; var topMostBaseType = cet . ResolvableTopMostBaseType ; foreach ( var child in ColumnMappings . Children ) { var msp = child as MappingScalarProperty ; if ( msp != null ) { List < Property > properties ; if ( ModelHelper . FindScalarPropertyPathByLocalName ( cet , msp . ColumnName , out properties ) ) { msp . CreateModelItem ( cpc , _context , properties ) ; } else if ( InheritanceMappingStrategy . TablePerType == mappingStrategy && ModelHelper . FindScalarPropertyPathByLocalName ( topMostBaseType , msp . ColumnName , out properties ) ) { msp . CreateModelItem ( cpc , _context , properties ) ; } } } } ; try { var cp = new CommandProcessor ( cpc ) ; cp . EnqueueCommand ( cmd ) ; cp . Invoke ( ) ; } catch { ModelItem = null ; ColumnMappings . ModelItem = null ; Parent . RemoveChild ( this ) ; throw ; } }
When a new table is mapped, we also set up the MappingColumnMappings view model item.
When a new table is mapped we also set up the MappingColumnMappings view model item .
// create a context if we weren't passed one // create the MappingFragment - if we already have a default EntityTypeMapping then just add // the MappingFragment to that mapping, otherwise if we already have an IsTypeOf // EntityTypeMapping then add the MappingFragment to that, otherwise create an IsTypeOf // EntityTypeMapping and add the MappingFragment to that // add post-invoke event to fix up our view model // fix up our view model // assign the table to our container node as well // now try and do some match ups between the entity and the table // now update the model
cpc
CommandProcessorContext
context
EditingContext
underlyingModelItem
EFElement