public static Dictionary <byte, object> Write(Dictionary <int, byte[]> screenshots) { using (var ctx = new DiscCtx(Discussions.ConfigManager.ConnStr)) { var res = new Dictionary <byte, object>(); //array of integers (shape Ids) var shapeIds = screenshots.Keys.ToArray(); res.Add((byte)DiscussionParamKey.ArrayOfInts, shapeIds); for (int i = 0; i < shapeIds.Length; i++) { var md = new MediaData { Data = screenshots[shapeIds[i]] }; ctx.AddToMediaDataSet(md); ctx.SaveChanges();//save here, need Id res.Add((byte)i, md.Id); } return(res); } }