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