1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00

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.
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);
file.Requery(usage.Context);
Files.Dereference(file.FileInfo);

View File

@ -49,18 +49,23 @@ namespace osu.Game.Database
default:
throw new ArgumentException($"{nameof(Requery)} does not have support for the provided model type", nameof(model));
}
void requeryFiles<T>(List<T> files, IDatabaseContextFactory databaseContextFactory) where T : class, INamedFileInfo
{
var dbContext = databaseContextFactory.Get();
foreach (var file in files)
{
Requery(file, dbContext);
}
}
}
private static void requeryFiles<T>(List<T> files, IDatabaseContextFactory databaseContextFactory) where T : class, INamedFileInfo
public static void Requery(this INamedFileInfo file, OsuDbContext dbContext)
{
var dbContext = databaseContextFactory.Get();
foreach (var file in files)
{
// 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 = dbContext.FileInfo.Find(file.FileInfoID);
}
// 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 = dbContext.FileInfo.Find(file.FileInfoID);
}
}
}