/// <summary>
        /// This returns the names of tables that have a set of foreign keys which map to all of the primary keys of the from/to tables
        /// </summary>
        /// <param name="fromKeys"></param>
        /// <param name="toKeys"></param>
        /// <param name="fromTableName"></param>
        /// <param name="toTableName"></param>
        /// <returns></returns>
        private IEnumerable <string> AllManyToManyTablesThatHaveTheRightForeignKeys(
            IEnumerable <EfColumnInfo> fromKeys, IEnumerable <EfColumnInfo> toKeys, string fromTableName, string toTableName)
        {
            //we form all the keys that we expect to see in the ReferencedTable/Col part of the many-to-many table
            var allKeys = fromKeys.Select(x => FormatHelpers.CombineTableAndColumnNames(fromTableName, x.SqlColumnName)).ToList();

            allKeys.AddRange(toKeys
                             .Select(x => FormatHelpers.CombineTableAndColumnNames(toTableName, x.SqlColumnName)));

            return(_foreignKeysGroupByParentTableName.Where(x => x.Item2.SequenceEqual(allKeys.OrderBy(y => y))).Select(x => x.Item1));
        }
 public EfRelationshipChecker(IEnumerable <EfTableInfo> efInfos,
                              SqlAllInfo allSqlInfo,
                              IList <SqlTableInfo> potentialManyToManyTables)
 {
     _efInfosDict = efInfos.ToDictionary(x => x.ClrClassType);
     _allSqlInfo  = allSqlInfo;
     _sqlInfoDict = allSqlInfo.TableInfos.ToDictionary(x => x.CombinedName);
     _potentialManyToManyTablesDict = potentialManyToManyTables.ToDictionary(x => x.CombinedName);
     //This dictionary allows us to backtrack the foreign keys to the correct many-to-many table
     _foreignKeysGroupByParentTableName = allSqlInfo.ForeignKeys
                                          .GroupBy(key => key.ParentTableNameWithScheme)
                                          .Select(x => new Tuple <string, List <string> >(x.Key,
                                                                                          x.Select(y => FormatHelpers.CombineTableAndColumnNames(y.ReferencedTableName, y.ReferencedColName)).OrderBy(y => y).ToList())).ToList();
 }