Exemplo n.º 1
0
        private static SortedListAllowDupes <DatabaseColumn> GetMappedColumnsForConceptualProperty(ConceptualProperty property)
        {
            var columns = new SortedListAllowDupes <DatabaseColumn>(new DatabaseColumnComparer());

            if (property != null)
            {
                foreach (var sp in property.GetAntiDependenciesOfType <ScalarProperty>())
                {
                    // only want scalar props for a mapping fragment, not for an association set mapping
                    if (sp.Parent is MappingFragment)
                    {
                        if (sp.ColumnName.Target == null)
                        {
                            Debug.Fail("Null target for " + sp.ToPrettyString());
                        }
                        else
                        {
                            // in the situation where property is in multiple EntityTypeMappings (an inheritance
                            // hierarchy) there can be multiple ScalarProperty anti-dependencies of property
                            // (one for each EntityTypeMapping) all of which map to the same DatabaseColumn -
                            // in this case only insert the first of these
                            var dbCol = DatabaseColumn.CreateFromProperty(sp.ColumnName.Target);
                            if (!columns.Contains(dbCol))
                            {
                                columns.Add(dbCol);
                            }
                        }
                    }
                }
            }
            return(columns);
        }
Exemplo n.º 2
0
        internal static int CompareListContents(SortedListAllowDupes <T> a, SortedListAllowDupes <T> b)
        {
            var enumA = a.GetEnumerator();
            var enumB = b.GetEnumerator();

            var aHasNext = enumA.MoveNext();
            var bHasNext = enumB.MoveNext();

            while (aHasNext && bHasNext)
            {
                var compVal = a._comparer.Compare(enumA.Current, enumB.Current);
                if (compVal != 0)
                {
                    return(compVal);
                }

                aHasNext = enumA.MoveNext();
                bHasNext = enumB.MoveNext();
            }

            if (aHasNext && !bHasNext)
            {
                return(1);
            }
            else if (!aHasNext && bHasNext)
            {
                return(-1);
            }

            // they are equals
            return(0);
        }
Exemplo n.º 3
0
        public int Compare(AssociationPropertyIdentity x, AssociationPropertyIdentity y)
        {
            var compVal = SortedListAllowDupes <DatabaseColumn> .CompareListContents(x.PrincipalColumns, y.PrincipalColumns);

            if (compVal == 0)
            {
                // left columns are equal, compare right columsn
                compVal = SortedListAllowDupes <DatabaseColumn> .CompareListContents(x.DependentColumns, y.DependentColumns);
            }
            return(compVal);
        }
Exemplo n.º 4
0
        public override bool Equals(object obj)
        {
            var that = obj as AssociationPropertyIdentity;

            if (that == null)
            {
                return(false);
            }

            if ((SortedListAllowDupes <DatabaseColumn> .CompareListContents(PrincipalColumns, that.PrincipalColumns) == 0) &&
                (SortedListAllowDupes <DatabaseColumn> .CompareListContents(DependentColumns, that.DependentColumns) == 0))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 5
0
        internal static SortedListAllowDupes <AssociationPropertyIdentity> CreateIdentitiesFromAssociationEndProperty(EndProperty endProp)
        {
            var props = new SortedListAllowDupes <AssociationPropertyIdentity>(AssociationPropertyIdentityComparer.Instance);

            foreach (var sProp in endProp.ScalarProperties())
            {
                var id          = new AssociationPropertyIdentity();
                var keyProperty = sProp.Name.Target as ConceptualProperty;

                id.PrincipalColumns = GetMappedColumnsForConceptualProperty(keyProperty);
                id.DependentColumns = new SortedListAllowDupes <DatabaseColumn>(new DatabaseColumnComparer());

                var sSideProperty = sProp.ColumnName.Target;
                if (null != sSideProperty)
                {
                    var stc = DatabaseColumn.CreateFromProperty(sSideProperty);
                    id.DependentColumns.Add(stc);
                    props.Add(id);
                }
            }
            return(props);
        }
Exemplo n.º 6
0
        internal static SortedListAllowDupes <AssociationPropertyIdentity> CreateIdentitiesFromReferentialConstraint(
            ReferentialConstraint referentialConstraint)
        {
            var principal = referentialConstraint.Principal;
            var dependent = referentialConstraint.Dependent;

            var identities = new SortedListAllowDupes <AssociationPropertyIdentity>(AssociationPropertyIdentityComparer.Instance);

            if (principal != null &&
                dependent != null)
            {
                // TODO:  deal with case where counts differ.
                if (principal.PropertyRefs.Count == dependent.PropertyRefs.Count)
                {
                    var pPropRefs = principal.PropertyRefs.GetEnumerator();
                    var dPropRefs = dependent.PropertyRefs.GetEnumerator();

                    while (pPropRefs.MoveNext() &&
                           dPropRefs.MoveNext())
                    {
                        var pProp = pPropRefs.Current.Name.Target as ConceptualProperty;
                        var dProp = dPropRefs.Current.Name.Target as ConceptualProperty;

                        if (pProp != null &&
                            dProp != null)
                        {
                            var id = new AssociationPropertyIdentity();
                            id.PrincipalColumns = GetMappedColumnsForConceptualProperty(pProp);
                            id.DependentColumns = GetMappedColumnsForConceptualProperty(dProp);
                            identities.Add(id);
                        }
                    }
                }
            }
            return(identities);
        }
 public int Compare(ReferentialConstraintIdentity x, ReferentialConstraintIdentity y)
 {
     return(SortedListAllowDupes <AssociationPropertyIdentity> .CompareListContents(x.PropertyIdentities, y.PropertyIdentities));
 }
Exemplo n.º 8
0
 internal AssociationEndIdentity(EndProperty endProp)
 {
     _propertyIdentities = AssociationPropertyIdentity.CreateIdentitiesFromAssociationEndProperty(endProp);
 }