mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Share file lookup workaround in ArchiveModelManager with workaround extensions class
This commit is contained in:
@ -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);
|
||||||
|
|
||||||
|
@ -49,18 +49,23 @@ 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
// 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 files)
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user