// TAG GROUPS AND TAGS private static IDictionary <Guid, IEnumerable <TagGroup> > SeedTags(ModelBuilder b, IEnumerable <Guid> userIds) { var dict = new Dictionary <Guid, IEnumerable <TagGroup> >(); foreach (var userId in userIds) { var tagGroups = ExerciseTagGroupsFactory.GetTagGroups().ToList(); foreach (var tagGroup in tagGroups) { tagGroup.Id = Guid.NewGuid(); tagGroup.ApplicationUserId = userId; foreach (var tag in tagGroup.Tags) { tag.TagGroupId = tagGroup.Id; tag.Id = Guid.NewGuid(); b.Entity <Tag>().HasData(tag); } } dict.Add(userId, tagGroups.Clone()); // clone the list tagGroups.ForEach(tg => { tg.Tags = null; // to avoid "Navigation property is set" error because you have to ONLY connect entities through pre-set IDs b.Entity <TagGroup>().HasData(tg); }); } return(dict); }