rephrased description of local context checking

This commit is contained in:
Aergwyn 2017-12-07 14:14:50 +01:00
parent 1dcbfab18e
commit 95955d68ef
1 changed files with 4 additions and 2 deletions

View File

@ -34,12 +34,14 @@ public void Add(BeatmapSetInfo beatmapSet)
foreach (var beatmap in beatmapSet.Beatmaps.Where(b => b.Metadata != null))
{
// check local context for metadata so we can reuse duplicates from the same set
// If we detect a new metadata object it'll be attached to the current context so it can be reused
// to prevent duplicate entries when persisting. To accomplish this we look in the cache (.Local)
// of the corresponding table (.Set<BeatmapMetadata>()) for matching entries to our criteria.
var contextMetadata = context.Set<BeatmapMetadata>().Local.SingleOrDefault(e => e.Equals(beatmap.Metadata));
if (contextMetadata != null)
beatmap.Metadata = contextMetadata;
else
context.BeatmapMetadata.Attach(beatmap.Metadata); // adding new to context
context.BeatmapMetadata.Attach(beatmap.Metadata);
}
context.BeatmapSetInfo.Attach(beatmapSet);