private void CreateOrGetSeries(Picture picture, List <SeriesData> series) { foreach (var seriesData in series) { Series seriesObj = null; if (!seriesData.Exists) { seriesObj = new Series { Name = seriesData.SuggestedName, Pictures = new HashSet <Picture>() }; } else { using (var repo = new SeriesRepository()) { seriesObj = repo.GetByName(seriesData.SuggestedName); } } seriesObj.Pictures.Add(picture); picture.Series.Add(seriesObj); } }