Example #1
0
        private AccountDto MapToDtoRecursive(Account source)
        {
            var target = AccountDto.MapToFromEntity(source);

            foreach (var item in source.Children)
            {
                var mappedChild = MapToDtoRecursive(item);
                target.Nodes.Add(mappedChild);
            }

            return(target);
        }
Example #2
0
        public AccountDto BuildTreeInMemory(Account rootNode)
        {
            var dtos = _dbContext.Accounts.OrderBy(a => a.Id).Where(a => a.Id > rootNode.Id).Select(AccountDto.MapToFromEntity).ToList();

            System.Console.WriteLine($"Building for {rootNode.Name}, with {dtos.Count} entities");

            int       counter = 0;
            Stopwatch sw      = Stopwatch.StartNew();

            var root       = AccountDto.MapToFromEntity(rootNode);
            var childNodes = GetChildNodes(root, dtos, new Dictionary <long, bool>(), ref counter);

            sw.Stop();
            System.Console.WriteLine($"Memory - Total iterations: {counter}. Took {sw.ElapsedMilliseconds} ms");

            root.Nodes = childNodes;
            return(root);
        }