foreach (var platId in s.PlatformIDs)
{
Platfrom p = new Platform { Id = platId };
context.Attach(p)
d.Platforms.Add(p);
}
You don't have to load the entity to make a relation. You just need a dummy with correct Id (which you already have). The dummy must be attached to the context.