public static IReadOnlyProperty?FindFirstPrincipal([NotNull] this IReadOnlyProperty property) { Check.NotNull(property, nameof(property)); var concreteProperty = property.AsProperty(); if (concreteProperty.ForeignKeys != null) { foreach (var foreignKey in concreteProperty.ForeignKeys) { for (var propertyIndex = 0; propertyIndex < foreignKey.Properties.Count; propertyIndex++) { if (property == foreignKey.Properties[propertyIndex]) { return(foreignKey.PrincipalKey.Properties[propertyIndex]); } } } } return(null); }
private static void AddPrincipals(IReadOnlyProperty property, List <IReadOnlyProperty> visited) { var concreteProperty = property.AsProperty(); if (concreteProperty.ForeignKeys != null) { foreach (var foreignKey in concreteProperty.ForeignKeys) { for (var propertyIndex = 0; propertyIndex < foreignKey.Properties.Count; propertyIndex++) { if (property == foreignKey.Properties[propertyIndex]) { var principal = foreignKey.PrincipalKey.Properties[propertyIndex]; if (!visited.Contains(principal)) { visited.Add(principal); AddPrincipals(principal, visited); } } } } } }