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); }
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); }
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); }