Exemplo n.º 1
0
        public IEdmEntitySet FindNavigationTarget(IEdmNavigationProperty property)
        {
            IEdmEntitySet entitySet;
            CsdlSemanticsNavigationProperty csdlSemanticsNavigationProperty = property as CsdlSemanticsNavigationProperty;

            if (csdlSemanticsNavigationProperty != null)
            {
                IEnumerator <IEdmEntityContainer> enumerator = this.Model.EntityContainers().GetEnumerator();
                using (enumerator)
                {
                    while (enumerator.MoveNext())
                    {
                        CsdlSemanticsEntityContainer current = (CsdlSemanticsEntityContainer)enumerator.Current;
                        IEnumerable <CsdlSemanticsAssociationSet> csdlSemanticsAssociationSets = current.FindAssociationSets(csdlSemanticsNavigationProperty.Association);
                        if (csdlSemanticsAssociationSets == null)
                        {
                            continue;
                        }
                        IEnumerator <CsdlSemanticsAssociationSet> enumerator1 = csdlSemanticsAssociationSets.GetEnumerator();
                        using (enumerator1)
                        {
                            while (enumerator1.MoveNext())
                            {
                                CsdlSemanticsAssociationSet    csdlSemanticsAssociationSet = enumerator1.Current;
                                CsdlSemanticsAssociationSetEnd end1 = csdlSemanticsAssociationSet.End1 as CsdlSemanticsAssociationSetEnd;
                                CsdlSemanticsAssociationSetEnd end2 = csdlSemanticsAssociationSet.End2 as CsdlSemanticsAssociationSetEnd;
                                if (csdlSemanticsAssociationSet.End1.EntitySet != this || csdlSemanticsNavigationProperty.To != csdlSemanticsAssociationSet.End2.Role)
                                {
                                    if (csdlSemanticsAssociationSet.End2.EntitySet != this || csdlSemanticsNavigationProperty.To != csdlSemanticsAssociationSet.End1.Role)
                                    {
                                        continue;
                                    }
                                    this.Model.SetAssociationSetName(csdlSemanticsAssociationSet.End2.EntitySet, property, csdlSemanticsAssociationSet.Name);
                                    if (end1 != null && end2 != null)
                                    {
                                        this.Model.SetAssociationSetAnnotations(end2.EntitySet, property, csdlSemanticsAssociationSet.DirectValueAnnotations, end2.DirectValueAnnotations, end1.DirectValueAnnotations);
                                    }
                                    entitySet = csdlSemanticsAssociationSet.End1.EntitySet;
                                    return(entitySet);
                                }
                                else
                                {
                                    this.Model.SetAssociationSetName(csdlSemanticsAssociationSet.End1.EntitySet, property, csdlSemanticsAssociationSet.Name);
                                    if (end1 != null && end2 != null)
                                    {
                                        this.Model.SetAssociationSetAnnotations(end1.EntitySet, property, csdlSemanticsAssociationSet.DirectValueAnnotations, end1.DirectValueAnnotations, end2.DirectValueAnnotations);
                                    }
                                    entitySet = csdlSemanticsAssociationSet.End2.EntitySet;
                                    return(entitySet);
                                }
                            }
                        }
                    }
                    return(null);
                }
                return(entitySet);
            }
            return(null);
        }
Exemplo n.º 2
0
        private IEdmEntitySet FindNavigationTargetHelper(IEdmNavigationProperty property)
        {
            CsdlSemanticsNavigationProperty navigationProperty = property as CsdlSemanticsNavigationProperty;

            if (navigationProperty != null)
            {
                foreach (CsdlSemanticsEntityContainer container in this.Model.EntityContainers())
                {
                    IEnumerable <CsdlSemanticsAssociationSet> associationSets = container.FindAssociationSets(navigationProperty.Association);
                    if (associationSets != null)
                    {
                        foreach (CsdlSemanticsAssociationSet associationSet in associationSets)
                        {
                            CsdlSemanticsAssociationSetEnd end1 = associationSet.End1 as CsdlSemanticsAssociationSetEnd;
                            CsdlSemanticsAssociationSetEnd end2 = associationSet.End2 as CsdlSemanticsAssociationSetEnd;
                            if (associationSet.End1.EntitySet == this && navigationProperty.To == associationSet.End2.Role)
                            {
                                this.Model.SetAssociationSetName(associationSet.End1.EntitySet, property, associationSet.Name);
                                if (end1 != null && end2 != null)
                                {
                                    this.Model.SetAssociationSetAnnotations(end1.EntitySet, property, associationSet.DirectValueAnnotations, end1.DirectValueAnnotations, end2.DirectValueAnnotations);
                                }

                                return(associationSet.End2.EntitySet);
                            }
                            else if (associationSet.End2.EntitySet == this && navigationProperty.To == associationSet.End1.Role)
                            {
                                this.Model.SetAssociationSetName(associationSet.End2.EntitySet, property, associationSet.Name);
                                if (end1 != null && end2 != null)
                                {
                                    this.Model.SetAssociationSetAnnotations(end2.EntitySet, property, associationSet.DirectValueAnnotations, end2.DirectValueAnnotations, end1.DirectValueAnnotations);
                                }

                                return(associationSet.End1.EntitySet);
                            }
                        }
                    }
                }
            }

            return(null);
        }