mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 02:13:21 +08:00
Workaround InvalidOperation exceptions
This commit is contained in:
parent
f1302d1600
commit
47b80d2474
@ -174,6 +174,22 @@ namespace osu.Game.Beatmaps
|
||||
if (beatmapSet.Beatmaps.Any(b => b.BaseDifficulty == null))
|
||||
throw new InvalidOperationException($"Cannot import {nameof(BeatmapInfo)} with null {nameof(BeatmapInfo.BaseDifficulty)}.");
|
||||
|
||||
var dbContext = ContextFactory.Get();
|
||||
|
||||
// Workaround System.InvalidOperationException
|
||||
// The instance of entity type 'RulesetInfo' cannot be tracked because another instance with the same key value for {'ID'} is already being tracked.
|
||||
foreach (var beatmap in beatmapSet.Beatmaps)
|
||||
{
|
||||
beatmap.Ruleset = dbContext.RulesetInfo.Find(beatmap.RulesetID);
|
||||
}
|
||||
|
||||
// Workaround System.InvalidOperationException
|
||||
// The instance of entity type 'FileInfo' cannot be tracked because another instance with the same key value for {'ID'} is already being tracked.
|
||||
foreach (var file in beatmapSet.Files)
|
||||
{
|
||||
file.FileInfo = dbContext.FileInfo.Find(file.FileInfoID);
|
||||
}
|
||||
|
||||
// check if a set already exists with the same online id, delete if it does.
|
||||
if (beatmapSet.OnlineBeatmapSetID != null)
|
||||
{
|
||||
|
@ -462,6 +462,10 @@ namespace osu.Game.Database
|
||||
// Dereference the existing file info, since the file model will be removed.
|
||||
if (file.FileInfo != null)
|
||||
{
|
||||
// Workaround System.InvalidOperationException
|
||||
// The instance of entity type 'FileInfo' cannot be tracked because another instance with the same key value for {'ID'} is already being tracked.
|
||||
file.FileInfo = usage.Context.FileInfo.Find(file.FileInfoID);
|
||||
|
||||
Files.Dereference(file.FileInfo);
|
||||
|
||||
// This shouldn't be required, but here for safety in case the provided TModel is not being change tracked
|
||||
@ -635,10 +639,12 @@ namespace osu.Game.Database
|
||||
{
|
||||
using (Stream s = reader.GetStream(file))
|
||||
{
|
||||
var fileInfo = files.Add(s);
|
||||
fileInfos.Add(new TFileModel
|
||||
{
|
||||
Filename = file.Substring(prefix.Length).ToStandardisedPath(),
|
||||
FileInfo = files.Add(s)
|
||||
FileInfo = fileInfo,
|
||||
FileInfoID = fileInfo.ID
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -142,6 +142,18 @@ namespace osu.Game.Skinning
|
||||
}
|
||||
}
|
||||
|
||||
protected override void PreImport(SkinInfo model)
|
||||
{
|
||||
var dbContext = ContextFactory.Get();
|
||||
|
||||
// Workaround System.InvalidOperationException
|
||||
// The instance of entity type 'FileInfo' cannot be tracked because another instance with the same key value for {'ID'} is already being tracked.
|
||||
foreach (var file in model.Files)
|
||||
{
|
||||
file.FileInfo = dbContext.FileInfo.Find(file.FileInfoID);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve a <see cref="Skin"/> instance for the provided <see cref="SkinInfo"/>
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user