Example #1
0
        /// <summary>
        /// M:N mappings in the database as M2NMapping objects
        /// </summary>
        /// <returns></returns>
        public List <M2NMapping> FindMappings()
        {
            List <M2NMapping> res        = new List <M2NMapping>();
            List <string>     twoColTabs = TwoColumnTables();
            List <List <FK> > twoColFKs  = new List <List <FK> >(from table in twoColTabs where FKs.ContainsKey(table) select FKs[table]);

            foreach (List <FK> currTabFKs in twoColFKs)
            {
                if (currTabFKs.Count == 2)
                {
                    // cannot say which table will use the mapping field (the one with more data)
                    //  ASK
                    res.Add(new M2NMapping(currTabFKs[0].refTable, currTabFKs[0].refColumn, currTabFKs[1].refTable,
                                           currTabFKs[1].refColumn, currTabFKs[0].myTable, currTabFKs[0].refColumn,
                                           currTabFKs[0].myColumn, currTabFKs[1].myColumn));

                    res.Add(new M2NMapping(currTabFKs[1].refTable, currTabFKs[1].refColumn, currTabFKs[0].refTable,
                                           currTabFKs[0].refColumn, currTabFKs[1].myTable, currTabFKs[1].refColumn,
                                           currTabFKs[1].myColumn, currTabFKs[0].myColumn));
                }
            }
            return(res);
        }