internal MappingLovEFElement(MappingEFElement mappingElement, string displayName)
 {
     Debug.Assert(mappingElement != null, "null mappingElement");
     Debug.Assert(displayName != null, "null displayName");
     _object = mappingElement;
     _displayName = displayName;
 }
        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));
        }
Exemple #3
0
 internal MappingLovEFElement(MappingEFElement mappingElement, string displayName)
 {
     Debug.Assert(mappingElement != null, "null mappingElement");
     Debug.Assert(displayName != null, "null displayName");
     _object      = mappingElement;
     _displayName = displayName;
 }
Exemple #4
0
 /// <summary>
 ///     Adds a child to the children collection.
 /// </summary>
 internal void AddChild(MappingEFElement newChild)
 {
     if (Children.Contains(newChild) == false)
     {
         _children.Add(newChild);
     }
 }
Exemple #5
0
 /// <summary>
 ///     Removes a child from the children collection.
 /// </summary>
 internal void RemoveChild(MappingEFElement child)
 {
     if (Children.Contains(child))
     {
         _children.Remove(child);
     }
 }
 public void Dispose()
 {
     if (_rootNode != null)
     {
         _rootNode.Dispose();
         _rootNode = null;
     }
 }
Exemple #7
0
 public void Dispose()
 {
     if (_rootNode != null)
     {
         _rootNode.Dispose();
         _rootNode = null;
     }
 }
 internal void Set(EFElement modelElement, MappingEFElement mapElement)
 {
     if (GetExisting(modelElement) == null)
     {
         _dict.Add(modelElement, mapElement);
     }
     else
     {
         _dict[modelElement] = mapElement;
     }
 }
Exemple #9
0
 private static void DeleteModelItemsRecursive(MappingEFElement melem, CommandProcessorContext cpc)
 {
     foreach (var childMappingEFElement in melem.Children)
     {
         DeleteModelItemsRecursive(childMappingEFElement, cpc);
     }
     if (melem.ModelItem != null &&
         melem.IsModelItemDeleted() == false)
     {
         melem.DeleteModelItem(cpc);
     }
 }
        internal MappingEFElement GetExistingOrParent(EFElement modelElement)
        {
            MappingEFElement result = null;

            while (result == null &&
                   modelElement != null)
            {
                if (!_dict.TryGetValue(modelElement, out result))
                {
                    modelElement = modelElement.Parent as EFElement;
                }
            }
            return(result);
        }
Exemple #11
0
        /// <summary>
        ///     Returns the index of the passed in child in this item's Children collection, returns -1 if it isn't found
        /// </summary>
        internal int IndexOfChild(MappingEFElement childToFind)
        {
            if (childToFind != null)
            {
                for (var i = 0; i < Children.Count; i++)
                {
                    if (Children[i] == childToFind)
                    {
                        return(i);
                    }
                }
            }

            return(-1);
        }
 private static void DeleteModelItemsRecursive(MappingEFElement melem, CommandProcessorContext cpc)
 {
     foreach (var childMappingEFElement in melem.Children)
     {
         DeleteModelItemsRecursive(childMappingEFElement, cpc);
     }
     if (melem.ModelItem != null
         && melem.IsModelItemDeleted() == false)
     {
         melem.DeleteModelItem(cpc);
     }
 }
 // <summary>
 //     Derived classes should override this and implement their own logic for removing an item from
 //     their children collection.
 // </summary>
 protected virtual void OnChildDeleted(MappingEFElement melem)
 {
 }
        // <summary>
        //     Returns the index of the passed in child in this item's Children collection, returns -1 if it isn't found
        // </summary>
        internal int IndexOfChild(MappingEFElement childToFind)
        {
            if (childToFind != null)
            {
                for (var i = 0; i < Children.Count; i++)
                {
                    if (Children[i] == childToFind)
                    {
                        return i;
                    }
                }
            }

            return -1;
        }
 // <summary>
 //     Removes a child from the children collection.
 // </summary>
 internal void RemoveChild(MappingEFElement child)
 {
     if (Children.Contains(child))
     {
         _children.Remove(child);
     }
 }
 // <summary>
 //     Adds a child to the children collection.
 // </summary>
 internal void AddChild(MappingEFElement newChild)
 {
     if (Children.Contains(newChild) == false)
     {
         _children.Add(newChild);
     }
 }
Exemple #17
0
 /// <summary>
 ///     Creates a new item.
 /// </summary>
 /// <param name="context">The current EditingContext; can be null</param>
 /// <param name="modelItem">The underlying model item; can be null for view model items that don't have an underlying model item yet.</param>
 /// <param name="parent">This item's parent; this should only be null for root level items</param>
 protected MappingEFElement(EditingContext context, EFElement modelItem, MappingEFElement parent)
 {
     _context   = context;
     _modelItem = modelItem;
     _parent    = parent;
 }
 internal override void EnsureTypeConverters(MappingEFElement element)
 {
     if (_converter == null
         || _currentElement != element)
     {
         _currentElement = element;
         _converter = null;
     }
 }
Exemple #19
0
 /// <summary>
 ///     Derived classes should override this and implement their own logic for removing an item from
 ///     their children collection.
 /// </summary>
 protected virtual void OnChildDeleted(MappingEFElement melem)
 {
 }
        internal static MappingEFElement GetNewOrExisting(EditingContext context, EFElement modelElement, MappingEFElement parent)
        {
            MappingEFElement result;

            var xref = GetModelToMappingModelXRef(context);

            result = xref.GetExisting(modelElement);
            if (result != null)
            {
                result.Parent = parent;
            }
            else
            {
                Type viewModelType;
                ModelTypeToViewModelType.TryGetValue(modelElement.GetType(), out viewModelType);
                if (viewModelType == null)
                {
                    // try the base class type
                    ModelTypeToViewModelType.TryGetValue(modelElement.GetType().BaseType, out viewModelType);
                }

                if (viewModelType != null)
                {
                    result = Activator.CreateInstance(viewModelType, context, modelElement, parent) as MappingEFElement;
                    xref.Add(modelElement, result);
                }
                else
                {
                    // implement a special case for entity type
                    // create the correct C- or S-space entity type in our view model
                    var entityType = modelElement as EntityType;
                    if (entityType != null)
                    {
                        var mappingDetailsInfo = context.Items.GetValue <MappingDetailsInfo>();
                        if (mappingDetailsInfo.EntityMappingMode == EntityMappingModes.Tables)
                        {
                            var entityModel = entityType.Parent as BaseEntityModel;
                            Debug.Assert(
                                entityModel != null,
                                "entityType's parent should be an EntityModel but received type "
                                + (entityType.Parent == null ? "NULL" : entityType.Parent.GetType().FullName));

                            if (entityModel.IsCSDL)
                            {
                                result =
                                    Activator.CreateInstance(typeof(MappingConceptualEntityType), context, modelElement, parent) as
                                    MappingEFElement;
                            }
                            else
                            {
                                result =
                                    Activator.CreateInstance(typeof(MappingStorageEntityType), context, modelElement, parent) as
                                    MappingEFElement;
                            }
                        }
                        else
                        {
                            result =
                                Activator.CreateInstance(typeof(MappingFunctionEntityType), context, modelElement, parent) as
                                MappingEFElement;
                        }
                        xref.Add(modelElement, result);
                    }

                    // special case for scalar properties
                    var scalarProperty = modelElement as ScalarProperty;
                    if (scalarProperty != null)
                    {
                        if (scalarProperty.Parent is MappingFragment ||
                            scalarProperty.Parent is ComplexProperty)
                        {
                            result =
                                Activator.CreateInstance(typeof(MappingScalarProperty), context, modelElement, parent) as MappingEFElement;
                        }
                        else
                        {
                            result =
                                Activator.CreateInstance(typeof(MappingEndScalarProperty), context, modelElement, parent) as
                                MappingEFElement;
                        }
                        xref.Add(modelElement, result);
                    }
                }
            }

            return(result);
        }
 // <summary>
 //     Creates a new item.
 // </summary>
 // <param name="context">The current EditingContext; can be null</param>
 // <param name="modelItem">The underlying model item; can be null for view model items that don't have an underlying model item yet.</param>
 // <param name="parent">This item's parent; this should only be null for root level items</param>
 protected MappingEFElement(EditingContext context, EFElement modelItem, MappingEFElement parent)
 {
     _context = context;
     _modelItem = modelItem;
     _parent = parent;
 }
Exemple #22
0
 internal MappingViewModel(EditingContext editingContext, MappingEFElement rootNode)
 {
     EditingContext = editingContext;
     _rootNode      = rootNode;
 }
        internal static MappingEFElement GetNewOrExisting(EditingContext context, EFElement modelElement, MappingEFElement parent)
        {
            MappingEFElement result;

            var xref = GetModelToMappingModelXRef(context);
            result = xref.GetExisting(modelElement);
            if (result != null)
            {
                result.Parent = parent;
            }
            else
            {
                Type viewModelType;
                ModelTypeToViewModelType.TryGetValue(modelElement.GetType(), out viewModelType);
                if (viewModelType == null)
                {
                    // try the base class type
                    ModelTypeToViewModelType.TryGetValue(modelElement.GetType().BaseType, out viewModelType);
                }

                if (viewModelType != null)
                {
                    result = Activator.CreateInstance(viewModelType, context, modelElement, parent) as MappingEFElement;
                    xref.Add(modelElement, result);
                }
                else
                {
                    // implement a special case for entity type
                    // create the correct C- or S-space entity type in our view model
                    var entityType = modelElement as EntityType;
                    if (entityType != null)
                    {
                        var mappingDetailsInfo = context.Items.GetValue<MappingDetailsInfo>();
                        if (mappingDetailsInfo.EntityMappingMode == EntityMappingModes.Tables)
                        {
                            var entityModel = entityType.Parent as BaseEntityModel;
                            Debug.Assert(
                                entityModel != null,
                                "entityType's parent should be an EntityModel but received type "
                                + (entityType.Parent == null ? "NULL" : entityType.Parent.GetType().FullName));

                            if (entityModel.IsCSDL)
                            {
                                result =
                                    Activator.CreateInstance(typeof(MappingConceptualEntityType), context, modelElement, parent) as
                                    MappingEFElement;
                            }
                            else
                            {
                                result =
                                    Activator.CreateInstance(typeof(MappingStorageEntityType), context, modelElement, parent) as
                                    MappingEFElement;
                            }
                        }
                        else
                        {
                            result =
                                Activator.CreateInstance(typeof(MappingFunctionEntityType), context, modelElement, parent) as
                                MappingEFElement;
                        }
                        xref.Add(modelElement, result);
                    }

                    // special case for scalar properties
                    var scalarProperty = modelElement as ScalarProperty;
                    if (scalarProperty != null)
                    {
                        if (scalarProperty.Parent is MappingFragment
                            || scalarProperty.Parent is ComplexProperty)
                        {
                            result =
                                Activator.CreateInstance(typeof(MappingScalarProperty), context, modelElement, parent) as MappingEFElement;
                        }
                        else
                        {
                            result =
                                Activator.CreateInstance(typeof(MappingEndScalarProperty), context, modelElement, parent) as
                                MappingEFElement;
                        }
                        xref.Add(modelElement, result);
                    }
                }
            }

            return result;
        }
 internal void Set(EFElement modelElement, MappingEFElement mapElement)
 {
     if (GetExisting(modelElement) == null)
     {
         _dict.Add(modelElement, mapElement);
     }
     else
     {
         _dict[modelElement] = mapElement;
     }
 }
 internal void Add(EFElement modelElement, MappingEFElement mapElement)
 {
     _dict.Add(modelElement, mapElement);
 }
 internal MappingViewModel(EditingContext editingContext, MappingEFElement rootNode)
 {
     EditingContext = editingContext;
     _rootNode = rootNode;
 }
 internal void Add(EFElement modelElement, MappingEFElement mapElement)
 {
     _dict.Add(modelElement, mapElement);
 }