public bool InsertMeanRel(string username, List <Dictionary <string, object> > list, DbTransaction tran) { try { //int mId = this.GetMeaningPKValue(); int rId = this.GetRelationPKValue(); Dictionary <string, object> rDic, mDic; foreach (Dictionary <string, object> dic in list) { //rDic = new Dictionary<string, object>(dic); //mDic = new Dictionary<string, object>(dic); //mDic.Add("ID", ++mId); //rDic.Add("ID", ++rId); //this.InsertOrUpdateMeaning(mDic, tran); UserMeanRelation relation = new UserMeanRelation(); relation.ID = ++rId; relation.Username = username; relation.MeaningId = ((Meanings)dic["Mean"]).Id; relation.Remark = (string)dic["Remark"]; this.InsertRelation(relation, tran); } } catch { return(false); } return(true); }
/// <summary> /// 插入relation /// </summary> /// <param name="username"></param> /// <param name="dic"></param> /// <returns></returns> public bool InsertMeanRel(string username, Dictionary <string, object> dic, DbTransaction tran) { /*先查询是否存在username->meaning的关系*/ Dictionary <string, object> condition = new Dictionary <string, object>(); condition.Add("username", username); condition.Add("desc", dic["Desc"]); object o = processor.QueryScalar("select 1 from UserMeanRelation where username=@username and MeaningDesc=@desc", condition); if (o == null || o.ToString() == "") { UserMeanRelation rel = new UserMeanRelation(); //if (dic.Keys.Contains("mID")) // rel.MeaningsID = (int)dic.First(p => p.Key == "mID").Value; //else //{ //查询meaning id // Meanings m = this.GetMeaningByName(dic["Desc"].ToString()); //if(m!=null&&m.Id!=0) //{ if (dic.Keys.Contains("ID")) { rel.ID = (int)dic.First(p => { return(p.Key == "ID"); }).Value; } else { int id = this.GetRelationPKValue(); rel.ID = id + 1; } rel.MeaningDesc = dic["Desc"].ToString(); rel.Username = username; rel.Remark = DateTime.Now.ToString(); return(processor.Insert <UserMeanRelation>(rel, tran)); //} } return(false); }
public void InsertRelation(UserMeanRelation relation, DbTransaction tran) { processor.Insert <UserMeanRelation>(relation, tran); }
public void InsertRelation(UserMeanRelation relation) { processor.Insert <UserMeanRelation>(relation, null); }