static LikenessContainer GetLikeness(MappingModel.Collections.CollectionMapping currentMapping, MappingModel.Collections.CollectionMapping mapping)
        {
            var currentMemberName = GetMemberName(currentMapping.Member);
            var mappingMemberName = GetMemberName(mapping.Member);

            return(new LikenessContainer
            {
                Collection = currentMapping,
                CurrentMemberName = currentMemberName,
                MappingMemberName = mappingMemberName,
                Differences = StringLikeness.EditDistance(currentMemberName, mappingMemberName)
            });
        }
 public virtual void ProcessCollection(MappingModel.Collections.CollectionMapping mapping)
 {
 }
        static MappingModel.Collections.CollectionMapping FindAlternative(IEnumerable <MappingModel.Collections.CollectionMapping> rs, MappingModel.Collections.CollectionMapping current, MappingModel.Collections.CollectionMapping otherSide)
        {
            var alternative = rs
                              .Where(x => x.ContainingEntityType == current.ContainingEntityType)
                              .Select(x => GetLikeness(x, otherSide))
                              .OrderBy(x => x.Differences)
                              .FirstOrDefault();

            if (alternative == null)
            {
                return(null);
            }

            return(alternative.Collection);
        }
        static MappingModel.Collections.CollectionMapping PairExactMatches(IEnumerable <MappingModel.Collections.CollectionMapping> rs, MappingModel.Collections.CollectionMapping current, IEnumerable <MappingModel.Collections.CollectionMapping> potentialOtherSides)
        {
            var otherSide = potentialOtherSides.Single();

            // got the other side of the relationship
            // lets make sure that the side that we're on now (mapping!)
            // is actually the relationship we want
            var mapping = FindAlternative(rs, current, otherSide) ?? current;

            mapping.OtherSide   = otherSide;
            otherSide.OtherSide = mapping;

            return(mapping);
        }
        static MappingModel.Collections.CollectionMapping PairFuzzyMatches(IEnumerable <MappingModel.Collections.CollectionMapping> rs, MappingModel.Collections.CollectionMapping current, IEnumerable <MappingModel.Collections.CollectionMapping> potentialOtherSides)
        {
            // no exact matches found, drop down to a levenshtein distance
            var mapping = current;

            var likenesses = potentialOtherSides
                             .Select(x => GetLikeness(x, current))
                             .Where(likeness_within_threshold)
                             .OrderBy(x => x.Differences);

            var first = likenesses.FirstOrDefault();

            if (first == null || AnyHaveSameLikeness(likenesses, first))
            {
                // couldn't find a definitive match, return nothing and we'll handle
                // this further up
                return(null);
            }

            var otherSide = likenesses.First().Collection;

            // got the other side of the relationship
            // lets make sure that the side that we're on now (mapping!)
            // is actually the relationship we want
            mapping = FindAlternative(rs, mapping, otherSide) ?? mapping;

            mapping.OtherSide   = otherSide;
            otherSide.OtherSide = mapping;

            return(mapping);
        }
 static bool both_collections_point_to_each_others_types(MappingModel.Collections.CollectionMapping left, MappingModel.Collections.CollectionMapping right)
 {
     return(left.ContainingEntityType == right.ChildType &&
            left.ChildType == right.ContainingEntityType);
 }