/// <summary> /// 构造函数 /// </summary> /// <param name="corrID"></param> public IRAPTreeCorr(int corrID) { _corrID = -corrID; db = DBContextFactory.Instance.CreateContext("IRAPContext"); _corrEntity = db.Set <ModelTreeCorrEntity>().FirstOrDefault(c => c.TreeCorrID == corrID); if (_corrEntity == null) { throw new Exception($"第 {corrID} 关联属性不存在!"); } _classifySet = db.Set <ModelTreeClassfiyEntity>().Where(c => c.TreeID == _corrID); _transientSet = db.Set <ModelTreeTransient>().Where(c => c.TreeID == _corrID); _namespaces = db.Set <SysNameSpaceEntity>().Where(c => c.PartitioningKey == 0 && c.LanguageID == 30); _statusSet = db.Set <ModelTreeStatus>().Where(c => c.TreeID == _corrID); }
/// <summary> /// 定义树关联 /// </summary> /// <param name="treeCorrID">树关联标识,这里是正数</param> /// <param name="corrAttrTBLName">关联一般属性</param> /// <param name="corrAttrTBLNameEx">管理扩展一般属性</param> /// <param name="trees">关联其他树数组</param> /// <returns></returns> public IRAPError DefineTreeCorr(int treeCorrID, string corrAttrTBLName, string corrAttrTBLNameEx, params int [] trees) { if (trees.Length > 12) { throw new Exception("暂不支持这么多关联,目前不能超过12个关联树。"); } //short maxID = _treeCorrSet.Max(c => c.TreeCorrID); var treeCorrEntity = _treeCorrSet.FirstOrDefault(c => c.TreeCorrID == treeCorrID); if (treeCorrEntity == null) { //新增 ModelTreeCorrEntity e = new ModelTreeCorrEntity() { TreeCorrID = (short)treeCorrID, CorrAttrTBLName = corrAttrTBLName, CorrAttrTBLNameEx = corrAttrTBLNameEx }; Type Ts = e.GetType(); for (int i = 0; i < trees.Length; i++) { int j = i + 1; string fname = "TreeID" + (j < 10 ? "0" + j.ToString() : j.ToString()); object v2 = Convert.ChangeType(trees[i], Ts.GetProperty(fname).PropertyType); Ts.GetProperty(fname).SetValue(e, v2, null); } _treeCorrSet.Add(e); } else { //修改 treeCorrEntity.CorrAttrTBLName = corrAttrTBLName; treeCorrEntity.CorrAttrTBLNameEx = corrAttrTBLNameEx; Type Ts = treeCorrEntity.GetType(); for (int i = 0; i < trees.Length; i++) { int j = i + 1; string fname = "TreeID" + (j < 10 ? "0" + j.ToString() : j.ToString()); object v2 = Convert.ChangeType(trees[i], Ts.GetProperty(fname).PropertyType); Ts.GetProperty(fname).SetValue(treeCorrEntity, v2, null); } } db.SaveChanges(); return(new IRAPError(0, "定义树关联成功!")); }