Share file lookup workaround in ArchiveModelManager with workaround extensions class

This commit is contained in:
Dean Herbert
2021-03-15 13:26:14 +09:00
parent 79d3379f55
commit 2904f479c6
2 changed files with 15 additions and 12 deletions

View File

@ -462,9 +462,7 @@ namespace osu.Game.Database
// Dereference the existing file info, since the file model will be removed. // Dereference the existing file info, since the file model will be removed.
if (file.FileInfo != null) if (file.FileInfo != null)
{ {
// Workaround System.InvalidOperationException file.Requery(usage.Context);
// 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); Files.Dereference(file.FileInfo);

View File

@ -49,13 +49,19 @@ namespace osu.Game.Database
default: default:
throw new ArgumentException($"{nameof(Requery)} does not have support for the provided model type", nameof(model)); throw new ArgumentException($"{nameof(Requery)} does not have support for the provided model type", nameof(model));
} }
}
private static void requeryFiles<T>(List<T> files, IDatabaseContextFactory databaseContextFactory) where T : class, INamedFileInfo void requeryFiles<T>(List<T> files, IDatabaseContextFactory databaseContextFactory) where T : class, INamedFileInfo
{ {
var dbContext = databaseContextFactory.Get(); var dbContext = databaseContextFactory.Get();
foreach (var file in files) foreach (var file in files)
{
Requery(file, dbContext);
}
}
}
public static void Requery(this INamedFileInfo file, OsuDbContext dbContext)
{ {
// Workaround System.InvalidOperationException // 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. // The instance of entity type 'FileInfo' cannot be tracked because another instance with the same key value for {'ID'} is already being tracked.
@ -63,4 +69,3 @@ namespace osu.Game.Database
} }
} }
} }
}