public IEnumerable<Ability> AllAbilities() { List<Ability> abilities = null; using (IDbConnection connection = database.CreateOpenConnection()) { abilities = VM_Ability.RetrieveAllAbilities(connection); foreach (Ability a in abilities) { a.Generation = VM_Generation.RetrieveSpecificGeneration(connection, a.Generation.Id); if (a.Generation != null && a.Generation.MainRegion != null) { a.Generation.MainRegion = VM_Region.RetrieveSpecificRegion(connection, a.Generation.MainRegion.Id); } a.AbilityChangelog = VM_Ability.RetrieveSpecificAbilityChangelog(connection, a.Id); foreach (AbilityChangelog ac in a.AbilityChangelog) { if (ac != null && ac.ChangedInVersionGroup != null) { ac.ChangedInVersionGroup = VM_VersionGroups.RetrieveSpecificVersionGroups(connection, ac.ChangedInVersionGroup.Id); ac.AbilityChangelogProse = VM_Ability.RetrieveSpecificAbilityChangelogProse(connection, ac.Id); foreach (AbilityChangelogProse acp in ac.AbilityChangelogProse) { acp.LocalLanguage = VM_Language.RetrieveSpecificLanguage(connection, acp.LocalLanguage.Id); } if (ac.ChangedInVersionGroup.Generation != null) { ac.ChangedInVersionGroup.Generation = VM_Generation.RetrieveSpecificGeneration(connection, ac.ChangedInVersionGroup.Generation.Id); if (ac.ChangedInVersionGroup.Generation.MainRegion != null) { ac.ChangedInVersionGroup.Generation.MainRegion = VM_Region.RetrieveSpecificRegion(connection, ac.ChangedInVersionGroup.Generation.MainRegion.Id); } } } } a.AbilityName = VM_Ability.RetrieveSpecificAbilityName(connection, a.Id); foreach (AbilityName an in a.AbilityName) { if (an != null && an.LocalLanguage != null) { an.LocalLanguage = VM_Language.RetrieveSpecificLanguage(connection, an.LocalLanguage.Id); } } a.AbilityProse = VM_Ability.RetrieveSpecificAbilityProse(connection, a.Id); foreach (AbilityProse ap in a.AbilityProse) { if (ap != null && ap.LocalLanguage != null) { ap.LocalLanguage = VM_Language.RetrieveSpecificLanguage(connection, ap.LocalLanguage.Id); } } } // foreach connection.Close(); } // Connection return abilities; }