Small DB-related refactoring

This commit is contained in:
TocoToucan 2017-10-09 23:30:32 +03:00
parent 41a90c8b11
commit ef417c6388
5 changed files with 4 additions and 10 deletions

View File

@ -27,14 +27,13 @@ public class BeatmapInfo : IEquatable<BeatmapInfo>, IJsonSerializable
public int BeatmapSetInfoId { get; set; }
[Required]
public BeatmapSetInfo BeatmapSet { get; set; }
public int? BeatmapMetadataId { get; set; }
public BeatmapMetadata Metadata { get; set; }
public int BeatmapDifficultyId { get; set; }
[Required]
public BeatmapDifficulty Difficulty { get; set; }
[NotMapped]

View File

@ -17,8 +17,6 @@ public class BeatmapSetInfo
public BeatmapMetadata Metadata { get; set; }
public int BeatmapMetadataId { get; set; }
public List<BeatmapInfo> Beatmaps { get; set; }
[NotMapped]

View File

@ -20,11 +20,8 @@ public OsuDbContext(string connectionString)
this.connectionString = connectionString;
}
public DbSet<BeatmapMetadata> BeatmapMetadata { get; set; }
public DbSet<BeatmapDifficulty> BeatmapDifficulty { get; set; }
public DbSet<BeatmapInfo> BeatmapInfo { get; set; }
public DbSet<BeatmapSetInfo> BeatmapSetInfo { get; set; }
public DbSet<BeatmapSetFileInfo> BeatmapSetFileInfo { get; set; }
public DbSet<DatabasedKeyBinding> DatabasedKeyBinding { get; set; }
public DbSet<FileInfo> FileInfo { get; set; }
public DbSet<RulesetInfo> RulesetInfo { get; set; }

View File

@ -56,7 +56,7 @@ public FileInfo Add(Stream data, bool reference = true)
{
string hash = data.ComputeSHA2Hash();
var existing = Connection.FileInfo.Where(f => f.Hash == hash).FirstOrDefault();
var existing = Connection.FileInfo.FirstOrDefault(f => f.Hash == hash);
var info = existing ?? new FileInfo { Hash = hash };

View File

@ -60,7 +60,7 @@ protected override void Prepare(bool reset = false)
{
var us = createRulesetInfo(r);
var existing = Connection.RulesetInfo.Where(ri => ri.InstantiationInfo == us.InstantiationInfo).FirstOrDefault();
var existing = Connection.RulesetInfo.FirstOrDefault(ri => ri.InstantiationInfo == us.InstantiationInfo);
if (existing == null)
Connection.RulesetInfo.Add(us);