Exemplo n.º 1
0
        internal override Dictionary <MappingLovEFElement, string> GetListOfValues(ListOfValuesCollection type)
        {
            var lov = new Dictionary <MappingLovEFElement, string>();

            if (type == ListOfValuesCollection.ThirdColumn)
            {
                var entityType = MappingConceptualEntityType.ConceptualEntityType;
                var properties = new List <Property>();

                // for TPT, show keys for the top-most base type
                if (entityType.HasResolvableBaseType)
                {
                    if (InheritanceMappingStrategy.TablePerType == ModelHelper.DetermineCurrentInheritanceStrategy(entityType))
                    {
                        // for TPT, show keys for the top-most base type
                        EntityType topMostBaseType = entityType.ResolvableTopMostBaseType;
                        properties.AddRange(topMostBaseType.ResolvableKeys);
                    }
                }

                // also show all properties of the current entity
                properties.AddRange(entityType.Properties());

                if (ScalarProperty != null)
                {
                    // add the row at the top that the user can click on to remove the item
                    lov.Add(LovDeletePlaceHolder, LovDeletePlaceHolder.DisplayName);
                }

                if (properties.Count == 0)
                {
                    if (ScalarProperty == null)
                    {
                        lov.Add(LovEmptyPlaceHolder, LovEmptyPlaceHolder.DisplayName);
                    }
                }
                else
                {
                    // add those remaining in our list
                    foreach (var prop in properties)
                    {
                        ColumnUtils.AddPropertyToListOfValues(lov, prop, null);
                    }
                }

                return(lov);
            }
            else
            {
                Debug.Fail("Unsupported lov type was sent");
            }

            return(base.GetListOfValues(type));
        }
Exemplo n.º 2
0
        internal override Dictionary <MappingLovEFElement, string> GetListOfValues(ListOfValuesCollection type)
        {
            var lov = new Dictionary <MappingLovEFElement, string>();

            if (type == ListOfValuesCollection.ThirdColumn)
            {
                var entityType = MappingFunctionEntityType.EntityType;
                var cet        = entityType as ConceptualEntityType;

                Debug.Assert(entityType == null || cet != null, "EntityType is not ConceptualEntityType");

                var propsFromSelf = new List <Property>();
                var propsFromNav  = new Dictionary <NavigationProperty, HashSet <Property> >();

                // show keys for the top-most base type
                if (cet.HasResolvableBaseType)
                {
                    propsFromSelf.AddRange(entityType.ResolvableKeys);
                }

                // show all properties of the entity
                propsFromSelf.AddRange(cet.SafeInheritedAndDeclaredProperties);

                // bug 568863: we need to show any "inherited" navigation properties as well
                foreach (var selfOrBaseType in cet.SafeSelfAndBaseTypes)
                {
                    // add properties for every type referenced by a navigation property
                    foreach (var nav in selfOrBaseType.NavigationProperties())
                    {
                        if (nav.FromRole.Status == BindingStatus.Known &&
                            nav.FromRole.Target.Type.Status == BindingStatus.Known &&
                            nav.ToRole.Status == BindingStatus.Known &&
                            nav.ToRole.Target.Type.Status == BindingStatus.Known &&
                            nav.ToRole.Target.Multiplicity.Value != ModelConstants.Multiplicity_Many)
                        {
                            ConceptualEntityType other = null;
                            if (nav.FromRole.Target.Type.Target == selfOrBaseType)
                            {
                                other = nav.ToRole.Target.Type.Target as ConceptualEntityType;
                            }
                            else
                            {
                                other = nav.FromRole.Target.Type.Target as ConceptualEntityType;
                            }

                            if (!propsFromNav.ContainsKey(nav))
                            {
                                propsFromNav[nav] = new HashSet <Property>();
                            }

                            // bug 568863, only include keys from reference types
                            foreach (var key in other.ResolvableTopMostBaseType.ResolvableKeys)
                            {
                                if (!propsFromNav[nav].Contains(key))
                                {
                                    propsFromNav[nav].Add(key);
                                }
                            }
                        }
                    }
                }

                if (ScalarProperty != null)
                {
                    // add the row at the top that the user can click on to remove the item
                    lov.Add(LovDeletePlaceHolder, LovDeletePlaceHolder.DisplayName);
                }

                if (propsFromSelf.Count == 0 &&
                    propsFromNav.Count == 0)
                {
                    if (ScalarProperty == null)
                    {
                        lov.Add(LovEmptyPlaceHolder, LovEmptyPlaceHolder.DisplayName);
                    }
                }
                else
                {
                    var displayName = String.Empty;

                    // add those remaining in our list
                    // Note: properties (even simple ScalarProperties that are not part of a ComplexProperty) are
                    //       added to the lov as a List<Property> whereas properties from the other end of a
                    //       NavigationProperty are added as a Property. This allows us to tell them apart (see
                    //       PropertyColumn.SetValue())
                    foreach (var prop in propsFromSelf)
                    {
                        ColumnUtils.AddPropertyToListOfValues(lov, prop, null);
                    }

                    var propsFromNavEnum = propsFromNav.GetEnumerator();
                    while (propsFromNavEnum.MoveNext())
                    {
                        foreach (var prop in propsFromNavEnum.Current.Value)
                        {
                            displayName = string.Format(
                                CultureInfo.CurrentCulture, "{0}.{1}",
                                propsFromNavEnum.Current.Key.LocalName.Value,
                                prop.LocalName.Value);
                            displayName = ColumnUtils.BuildPropertyDisplay(displayName, prop.TypeName);

                            lov.Add(new MappingLovEFElement(prop, displayName), displayName);
                        }
                    }
                }

                return(lov);
            }
            else
            {
                Debug.Fail("Unsupported lov type (" + type.ToString() + ") was sent");
            }

            return(base.GetListOfValues(type));
        }