/// <summary> /// 添加各种选项 /// </summary> /// <param name="articleId">文章ID</param> /// <param name="ops">一级选项名字,二级选项名字</param> /// <returns></returns> public static bool addOptions(int articleId, Dictionary <string, string> ops) { List <int> opsls = new List <int>(); foreach (KeyValuePair <string, string> s in ops) { opsls.Add(LabelHelper.getOptionId(s.Key, s.Value)); } try { using (var db = new PaperDbEntities()) { //增加所有选项 foreach (int id in opsls) { TypeConnection tc = new TypeConnection(); tc.ArticleId = articleId; tc.OptionId = id; db.TypeConnection.Add(tc); } db.SaveChanges(); return(true); } } catch (Exception ex) { return(false); } }