public SqlHierarchyId GetNewDocumentNode(SqlHierarchyId parentNode) { var command = new CommandDefinition( commandText: GetNewDocumentNoteSql, new { ParentNode = parentNode.ToString(), }); return(SqlHierarchyId.Parse(_connection.QuerySingle <string>(command).ToString())); }
private static Member GetByMatrixId(SqlHierarchyId matrixId) { string query = string.Format(@"SELECT TOP 1 UserId FROM Users WHERE MatrixId = '{0}'", matrixId.ToString()); object userIdObject = TableHelper.SelectScalar(query); if (userIdObject is DBNull) { return(null); } return(new Member((int)userIdObject)); }
public string WhereClause(ArrayList collapsed) { System.Text.StringBuilder wc = new System.Text.StringBuilder(""); foreach (string item in collapsed) { SqlHierarchyId itemHid = Conversions.Bytes2HierarchyId(GetHid(item)); wc.Append("AND ((cast(hid as hierarchyid).IsDescendantOf('" + itemHid.ToString() + "')=0 or cast(hid as hierarchyid) = '" + itemHid.ToString() + "'))"); } string result = wc.ToString(); if (result == "") { result = "1=1"; } else { result = result.Substring(3); } return(result); }
private async Task <AccountHierarchy> AddToParent(AccountHierarchy entity, long?parentId, bool autoCommit = true) { if (!parentId.HasValue) { SqlHierarchyId parentLevel = SqlHierarchyId.GetRoot(); entity.ParentId = null; entity.UplinkId = null; entity.LevelPath = parentLevel.ToString(); } else { var parent = await _dbContext.AccountHierarchies.Where(x => x.Id == parentId) .Include(x => x.Children) .FirstOrDefaultAsync(); SqlHierarchyId parentLevel = SqlHierarchyId.Parse(parent.LevelPath); var lastSibling = parent.Children.OrderByDescending(x => x.LevelPath).FirstOrDefault(); string levelPath = null; if (entity.Leg == 2) { if (lastSibling == null) { levelPath = parent.LevelPath + "2/"; } else { SqlHierarchyId newLevel = parentLevel.GetDescendant(SqlHierarchyId.Parse(lastSibling.LevelPath), SqlHierarchyId.Null); levelPath = newLevel.ToString(); } } else if (entity.Leg == 1) // in any other case - put it on the left { if (lastSibling == null) { levelPath = parent.LevelPath + "1/"; } else { SqlHierarchyId newLevel = parentLevel.GetDescendant(SqlHierarchyId.Null, SqlHierarchyId.Parse(lastSibling.LevelPath)); levelPath = newLevel.ToString(); } } else { throw new ArgumentOutOfRangeException("Leg", "Invalid value for leg: " + entity.Leg); } entity.LevelPath = levelPath; entity.ParentId = parentId; } var result = (await _dbContext.AccountHierarchies.AddAsync(entity)).Entity; if (autoCommit) { await _dbContext.SaveChangesAsync(); } return(result); }
public void GetObjectData(object obj, SerializationInfo info, StreamingContext context) { SqlHierarchyId shi = (SqlHierarchyId)obj; info.AddValue("route", shi.ToString()); }
public void Print() { Console.WriteLine((Level.ToString() + "\t" + Name + "\t" + Salary + "\t" + Position)); }