private static void GetMappingPatterns(Role towardsRole, Role fromRole, out MappingUniquenessPattern uniquenessPattern, out MappingMandatoryPattern mandatoryPattern) { if (towardsRole.FactType is SubtypeFact) { uniquenessPattern = MappingUniquenessPattern.Subtype; mandatoryPattern = (towardsRole is SubtypeMetaRole) ? MappingMandatoryPattern.TowardsRoleMandatory : MappingMandatoryPattern.OppositeRoleMandatory; } else { bool towardsRoleUnique; bool towardsRoleMandatory; bool towardsRoleImpliedMandatory; bool fromRoleUnique; bool fromRoleMandatory; bool fromRoleImpliedMandatory; bool oneToOne = false; GetUniqueAndMandatory(towardsRole, out towardsRoleUnique, out towardsRoleMandatory, out towardsRoleImpliedMandatory); GetUniqueAndMandatory(fromRole, out fromRoleUnique, out fromRoleMandatory, out fromRoleImpliedMandatory); uniquenessPattern = towardsRoleUnique ? ((oneToOne = fromRoleUnique) ? MappingUniquenessPattern.OneToOne : MappingUniquenessPattern.OneToMany) : MappingUniquenessPattern.ManyToOne; if (oneToOne && (fromRoleImpliedMandatory ^ towardsRoleImpliedMandatory)) { // Adjust mandatory patterns to ignore implied mandatory on naturally asymmetric // one-to-one relationships. if (fromRoleImpliedMandatory) { fromRoleMandatory = !towardsRoleMandatory; } else { towardsRoleMandatory = !fromRoleMandatory; } } mandatoryPattern = towardsRoleMandatory ? (fromRoleMandatory ? MappingMandatoryPattern.BothRolesMandatory : MappingMandatoryPattern.TowardsRoleMandatory) : (fromRoleMandatory ? MappingMandatoryPattern.OppositeRoleMandatory : MappingMandatoryPattern.NotMandatory); } }
/// <summary> /// Update the <see cref="MandatoryPattern"/> and <see cref="UniquenessPattern"/> if the current constraints /// on the associated <see cref="FactType"/> cannot change the <see cref="Depth"/> or direction of the mapping. /// If the current mapping can be influenced, then do nothing and return <see langword="false"/> /// </summary> /// <returns><see langword="true"/> if the current set of constraints on the FactType cannot change the current mapping depth or direction.</returns> public bool SynchronizeMappingPatterns() { bool retVal = false; MappingUniquenessPattern newUniquenessPattern; MappingMandatoryPattern newMandatoryPattern; GetMappingPatterns(TowardsRole, out newUniquenessPattern, out newMandatoryPattern); MappingUniquenessPattern oldUniquenessPattern = UniquenessPattern; if (newUniquenessPattern == oldUniquenessPattern) { MappingMandatoryPattern oldMandatoryPattern = MandatoryPattern; if (newMandatoryPattern == oldMandatoryPattern) { retVal = true; } else { switch (oldUniquenessPattern) { case MappingUniquenessPattern.OneToMany: // Mandatory constraints to not affect one-to-many mapping retVal = true; break; case MappingUniquenessPattern.OneToOne: // UNDONE: The answers here assume that a reduced set of // choices will result in the same answer. This is a conjecture // at this point that is likely to be true, but we're not sure. switch (oldMandatoryPattern) { case MappingMandatoryPattern.BothRolesMandatory: switch (newMandatoryPattern) { case MappingMandatoryPattern.TowardsRoleMandatory: case MappingMandatoryPattern.NotMandatory: retVal = Depth == MappingDepth.Shallow; break; case MappingMandatoryPattern.OppositeRoleMandatory: retVal = true; break; } break; case MappingMandatoryPattern.OppositeRoleMandatory: case MappingMandatoryPattern.TowardsRoleMandatory: retVal = newMandatoryPattern == MappingMandatoryPattern.NotMandatory && Depth == MappingDepth.Shallow; break; } break; } if (retVal) { MandatoryPattern = newMandatoryPattern; } } } else if (oldUniquenessPattern == MappingUniquenessPattern.OneToOne && newUniquenessPattern == MappingUniquenessPattern.OneToMany && Depth == MappingDepth.Shallow) { // Shallow towards current TowardsRole is the only remaining possibility, nothing will change retVal = true; MandatoryPattern = newMandatoryPattern; UniquenessPattern = newUniquenessPattern; } return(retVal); }
private static void GetMappingPatterns(RoleBase towardsRole, out MappingUniquenessPattern uniquenessPattern, out MappingMandatoryPattern mandatoryPattern) { Role role = towardsRole.Role; GetMappingPatterns(role, role.OppositeRoleAlwaysResolveProxy.Role, out uniquenessPattern, out mandatoryPattern); }