diff --git a/osu.Game/Input/KeyBindingStore.cs b/osu.Game/Input/KeyBindingStore.cs index 54cf48bc2a..bebbb471ac 100644 --- a/osu.Game/Input/KeyBindingStore.cs +++ b/osu.Game/Input/KeyBindingStore.cs @@ -36,29 +36,31 @@ namespace osu.Game.Input private void insertDefaults(IEnumerable defaults, int? rulesetId = null, int? variant = null) { - var context = GetContext(); - - // compare counts in database vs defaults - foreach (var group in defaults.GroupBy(k => k.Action)) + using (var context = GetContext()) + using (var transaction = context.Database.BeginTransaction()) { - int count = query(context, rulesetId, variant).Count(k => (int)k.Action == (int)group.Key); - int aimCount = group.Count(); + // compare counts in database vs defaults + foreach (var group in defaults.GroupBy(k => k.Action)) + { + int count = query(context, rulesetId, variant).Count(k => (int)k.Action == (int)group.Key); + int aimCount = group.Count(); - if (aimCount <= count) - continue; + if (aimCount <= count) + continue; - foreach (var insertable in group.Skip(count).Take(aimCount - count)) - // insert any defaults which are missing. - context.DatabasedKeyBinding.Add(new DatabasedKeyBinding - { - KeyCombination = insertable.KeyCombination, - Action = insertable.Action, - RulesetID = rulesetId, - Variant = variant - }); + foreach (var insertable in group.Skip(count).Take(aimCount - count)) + // insert any defaults which are missing. + context.DatabasedKeyBinding.Add(new DatabasedKeyBinding + { + KeyCombination = insertable.KeyCombination, + Action = insertable.Action, + RulesetID = rulesetId, + Variant = variant + }); + } + + context.SaveChanges(transaction); } - - context.SaveChanges(); } ///