diff --git a/osu.Game/Beatmaps/BeatmapInfo.cs b/osu.Game/Beatmaps/BeatmapInfo.cs index d5f89d1d66..7ad1416642 100644 --- a/osu.Game/Beatmaps/BeatmapInfo.cs +++ b/osu.Game/Beatmaps/BeatmapInfo.cs @@ -19,19 +19,20 @@ namespace osu.Game.Beatmaps //TODO: should be in database public int BeatmapVersion; + [NotMapped] public int? BeatmapOnlineInfoId { get; set; } + [NotMapped] public int? BeatmapSetOnlineInfoId { get; set; } public int BeatmapSetInfoId { get; set; } public BeatmapSetInfo BeatmapSet { get; set; } - public int BeatmapMetadataId { get; set; } + public int? BeatmapMetadataId { get; set; } public BeatmapMetadata Metadata { get; set; } - //[Required] public int BeatmapDifficultyId { get; set; } public BeatmapDifficulty Difficulty { get; set; } diff --git a/osu.Game/Beatmaps/BeatmapMetadata.cs b/osu.Game/Beatmaps/BeatmapMetadata.cs index fbe8c08eb2..698d37a16c 100644 --- a/osu.Game/Beatmaps/BeatmapMetadata.cs +++ b/osu.Game/Beatmaps/BeatmapMetadata.cs @@ -12,6 +12,7 @@ namespace osu.Game.Beatmaps [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } + [NotMapped] public int? BeatmapSetOnlineInfoId { get; set; } public string Title { get; set; } diff --git a/osu.Game/Beatmaps/BeatmapSetInfo.cs b/osu.Game/Beatmaps/BeatmapSetInfo.cs index f3cc01bb08..f7887b31cb 100644 --- a/osu.Game/Beatmaps/BeatmapSetInfo.cs +++ b/osu.Game/Beatmaps/BeatmapSetInfo.cs @@ -12,6 +12,7 @@ namespace osu.Game.Beatmaps [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } + [NotMapped] public int? BeatmapSetOnlineInfoId { get; set; } public BeatmapMetadata Metadata { get; set; } diff --git a/osu.Game/Beatmaps/BeatmapStore.cs b/osu.Game/Beatmaps/BeatmapStore.cs index ece006a818..eeaab60dd2 100644 --- a/osu.Game/Beatmaps/BeatmapStore.cs +++ b/osu.Game/Beatmaps/BeatmapStore.cs @@ -137,22 +137,22 @@ namespace osu.Game.Beatmaps public BeatmapSetInfo QueryBeatmapSet(Func query) { - return Connection.BeatmapSetInfo.FirstOrDefault(query); + return Connection.BeatmapSetInfo.Include(b=>b.Beatmaps).Include(b=>b.Metadata).FirstOrDefault(query); } public List QueryBeatmapSets(Expression> query) { - return Connection.BeatmapSetInfo.Where(query).ToList(); + return Connection.BeatmapSetInfo.Include(b => b.Beatmaps).Include(b => b.Metadata).Include(b=>b.Files).Where(query).ToList(); } public BeatmapInfo QueryBeatmap(Func query) { - return Connection.BeatmapInfo.FirstOrDefault(query); + return Connection.BeatmapInfo.Include(b => b.BeatmapSet).Include(b => b.Metadata).Include(b=>b.Ruleset).FirstOrDefault(query); } public List QueryBeatmaps(Expression> query) { - return Connection.BeatmapInfo.Where(query).ToList(); + return Connection.BeatmapInfo.Include(b => b.BeatmapSet).Include(b => b.Metadata).Where(query).ToList(); } } } diff --git a/osu.Game/Database/OsuDbContext.cs b/osu.Game/Database/OsuDbContext.cs index 41ae0711f4..57be32359c 100644 --- a/osu.Game/Database/OsuDbContext.cs +++ b/osu.Game/Database/OsuDbContext.cs @@ -47,9 +47,6 @@ namespace osu.Game.Database modelBuilder.Entity().HasIndex(b => b.Name).IsUnique(); modelBuilder.Entity().HasIndex(b => b.InstantiationInfo).IsUnique(); modelBuilder.Entity().HasIndex(b => b.Available); - //modelBuilder.Entity().HasOne(b => b.BeatmapSetOnlineInfo).WithOne(bs => bs.BeatmapMetadata).OnDelete(DeleteBehavior.SetNull); - //modelBuilder.Entity().HasOne(b => b.BeatmapSetOnlineInfo).WithOne(bs => bs.BeatmapSetInfo).OnDelete(DeleteBehavior.SetNull); - //modelBuilder.Entity().HasOne(b => b.BeatmapSetOnlineInfo).WithMany(bs => bs.Beatmaps).OnDelete(DeleteBehavior.SetNull); } } } diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 8905c91b92..fc25cd7776 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -83,8 +83,6 @@ namespace osu.Game protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) => dependencies = new DependencyContainer(base.CreateLocalDependencies(parent)); - private OsuDbContext dbContext; - private OsuDbContext createDbContext() { var connectionString = Host.Storage.GetDatabaseConnectionString(@"client"); @@ -106,7 +104,7 @@ namespace osu.Game dependencies.Cache(this); dependencies.Cache(LocalConfig); - dbContext = createDbContext(); + using (var dbContext = createDbContext()) if (dbContext.Database.GetPendingMigrations().Any()) dbContext.Database.Migrate(); @@ -116,11 +114,11 @@ namespace osu.Game Token = LocalConfig.Get(OsuSetting.Token) }); - dependencies.Cache(RulesetStore = new RulesetStore(dbContext)); - dependencies.Cache(FileStore = new FileStore(dbContext, Host.Storage)); - dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, FileStore, dbContext, RulesetStore, API, Host)); - dependencies.Cache(ScoreStore = new ScoreStore(Host.Storage, dbContext, Host, BeatmapManager, RulesetStore)); - dependencies.Cache(KeyBindingStore = new KeyBindingStore(dbContext, RulesetStore)); + dependencies.Cache(RulesetStore = new RulesetStore(createDbContext())); + dependencies.Cache(FileStore = new FileStore(createDbContext(), Host.Storage)); + dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, FileStore, createDbContext(), RulesetStore, API, Host)); + dependencies.Cache(ScoreStore = new ScoreStore(Host.Storage, createDbContext(), Host, BeatmapManager, RulesetStore)); + dependencies.Cache(KeyBindingStore = new KeyBindingStore(createDbContext(), RulesetStore)); dependencies.Cache(new OsuColour()); //this completely overrides the framework default. will need to change once we make a proper FontStore. @@ -247,8 +245,6 @@ namespace osu.Game LocalConfig.Save(); } - dbContext?.Dispose(); - base.Dispose(isDisposing); } } diff --git a/osu.Game/Screens/Menu/Intro.cs b/osu.Game/Screens/Menu/Intro.cs index 66e6da3af9..5881325f24 100644 --- a/osu.Game/Screens/Menu/Intro.cs +++ b/osu.Game/Screens/Menu/Intro.cs @@ -22,7 +22,7 @@ namespace osu.Game.Screens.Menu { private readonly OsuLogo logo; - private const string menu_music_beatmap_hash = "715a09144f885d746644c1983e285044"; + private const string menu_music_beatmap_hash = "3c8b1fcc9434dbb29e2fb613d3b9eada9d7bb6c125ceb32396c3b53437280c83"; /// /// Whether we have loaded the menu previously. @@ -91,7 +91,6 @@ namespace osu.Game.Screens.Menu setInfo = beatmaps.Import(new OszArchiveReader(game.Resources.GetStream(@"Tracks/circles.osz"))); setInfo.Protected = true; - beatmaps.Delete(setInfo); } } @@ -101,6 +100,7 @@ namespace osu.Game.Screens.Menu welcome = audio.Sample.Get(@"welcome"); seeya = audio.Sample.Get(@"seeya"); + beatmaps.Delete(setInfo); } protected override void OnEntering(Screen last)