internal static MappingViewModel CreateViewModel(EditingContext ctx, EFObject selection)
        {
            // clear out the xref so its clean for this new view model
            var xref = ModelToMappingModelXRef.GetModelToMappingModelXRef(ctx);

            xref.Clear();

            // we might be creating a view model for an entity or an association or a FunctionImport
            var entityType  = selection as EntityType;
            var association = selection as Association;
            var fim         = selection as FunctionImportMapping;

            // create the view model root
            MappingEFElement root = null;

            if (entityType != null)
            {
                root = ModelToMappingModelXRef.GetNewOrExisting(ctx, entityType, null);
            }
            else if (association != null)
            {
                root = ModelToMappingModelXRef.GetNewOrExisting(ctx, association, null);
            }
            else if (fim != null)
            {
                root = ModelToMappingModelXRef.GetNewOrExisting(ctx, fim, null);
            }
            else
            {
                throw new ArgumentException("selection");
            }

            return(new MappingViewModel(ctx, root));
        }