Right now I have the following table schema:
Node_Id (INT)| NodeName (nvarchar(40)) | ParentNode(int, FK)
I want to retrieve hierarchical tree from that structure: structure simmilar to this one: {NodeId, NodeName, IEnumerable<Node> Children, bool hasChildren}
I see two solutions for this problem: first is tree traversal. I mean to load root nodes (where parent=null) and then for each node load it's children and recursively do this for these nodes. But each child load results in additional query to DB which is performance hit.
Another option I see would be to load flat strucure from database (the same as table schema) and then from it build hierarchical structure. That is performance hit to application server.
I was wondering if there any other solutions?
If you don't need to show all the tree children at once, immediately, you could load based on a specified parent node and then load on demand as the user expands the tree children. This would result in a lighter load on the application and DB servers.
In addition to the solutions you already mentioned you also have the possibility to use connect by / start with in oracle sql.
See this link for further infos: http://docs.oracle.com/cd/B19306_01/server.102/b14200/queries003.htm
Related
I'm currently testing various reporting tools and came across to List & Label from Combit, which makes a very solid impression. As part of a PoC, I first integrated it into a simple C# Winforms application and attached a SQL Server database.
...
using(ListLabel myLL = new ListLabel())
{
SqlConnection connection = new SqlConnection(Properties.Settings.Default.ConnectionString);
myLL.DataSource = new SqlConnectionDataProvider(connection);
myLL.Design();
}
...
However, I don't understand why with the data structure in the designer I can't then also see the relational structure in/from the database.... all relations seem to be just ignored. I can only see all tables at the root level - even though they are a relation in the SQL Server database.
Couldn't find any information for this so far unfortunately - ideas?
Actually, it's all there usually. You should be able to see the full structure, as soon as you add a report container:
This way, you can add e.g. "Order Details" either as a sub element of the customers (like shown in the screenshot) or as a top level element (if I had selected it from the root of the list).
The field tree on the other hand just shows the available tables with their contents ("fields"). As each table may appear in different levels of the hierarchy, it's only added once to the tree, while the hierarchy is defined when adding a new table.
One exception from this rule is the 1:1 related identifiers of parent tables. As it might well be required to print e.g. Customer data related to an order line in a "Orders" table, you cann access them directly from the field tree:
Thus, you actually do see the relations there, albeit in reverse order. While this might seem confusing at first it really makes sense once you get your head around the concept.
I'm completely new in the GraphDatabase world and also in writing Cypher Statements.
I have a project, where I want to store wiring diagram information inside a graph database (Neo4J). There are different types of Nodes like f.e. WiringDiagram [WD] Node (will be my start node in many cases) and regarding this WD Node all components like fuseboxes, ICU's or sensors are linked via relationships. Plugs also can contain Pins, and Pins are connected via Connectionlines.
The first version is already stored in the Neo4j Database, have a look at the following image.
Now I have a question which way is best to post-process this data. I want the data extracted for one specific wiring Diagram.
So if I would say I want all information about WiringDiagram with ID 123, I should get all components, Pins and Connectenlines which are there. How should the Cypher look like here?
I want the data best in C# Data models (if possible). Because afterwards I want to try to generate an SVG out of the data.
As you can see in the image, the cypher statement looks currently like this. "MATCH (w:WiringDiagram)<-[r:partOf]-(n)-[*2..]-(l) RETURN * LIMIT 50" But with this statement I get strange results in my C# Project...
I would be happy about any help. I'm also open to go forward with another programming language if it fits better for this approach. Happy to hear any suggestions
I found an APOC function which currently does what I want to.
Get All nodes after the searched one, and give the complete subgroup with relationships back.
Looks currently good.
Any suggestion how to store this data back in data models in C#? (whats best way?)
var result = tx.Run($#"MATCH (p:WiringDiagram {{wiringid:1}})
CALL apoc.path.subgraphAll(p, {{
relationshipFilter:
""partOf|has_pin|connectedWith"",
filterStartNode:false,
minLevel: 0,
maxLevel: 10
}})
YIELD nodes, relationships
RETURN nodes, relationships;");
And after that I've got two lists, one with all the nodes, and one with all relationships with start/endnode id
I'm a PHP programmer, and I'm trying to understand some code which I think is ASP.NET. This is also my first foray into XML. I don't have access to a Windows box to test on.
I need to produce XML output that third-party code can use. The third party wants to use our data instead of the data source they are currently using. I don't want to replicate the current XML structure exactly because it doesn't map well to our data.
The structure of the current XML is very flat. There are only a few nested elements and the third party doesn't make use of any of them. The third party does have a sub-contracted programmer, but he is very busy. Also, I want to understand, for myself, how this works.
This is an excerpt from a plugin for a custom CMS:
Dim obj_set As New Data.DataSet()
Using obj_reader As New System.Xml.XmlTextReader("http://www.example.com/xml_output.php")
obj_set.ReadXml(obj_reader)
End Using
Dim obj_view As Data.DataView = obj_set.Tables("profile").DefaultView
obj_view.Sort = "cname"
Dim obj_data As Data.DataTable = obj_view.ToTable()
So from what I have gathered so far, this code
reads the XML file into a DataSet
sorts the profile table by cname
creates a new DataTable from the sorted view
There is other code that stores the new table to, and retrieves it from, cache. Then there is code that loops through the table rows and maps the column names to template variables.
Sample excerpt of current XML structure:
<profiles>
<profile>
<cname>ABC Corporation</cname>
<fname>John</fname>
<lname>Smith</lname>
<sector>Widgets</sector>
<subsectors>
<subsector>Basic Widgets</subsector>
<subsector>Fancy Widgets</subsector>
</subsectors>
</profile>
</profiles>
So what happens to the subsectors data? Does the reader create a separate table for it? If so, how are the tables related?
Our data includes multiple contacts per company. I could just create multiple elements at the top level fname1, fname2, fname3 to keep the flat structure. But I was thinking a nested structure makes sense for this kind of data. The problem is that I don't understand if such a structural change is compatible with the plugin code.
What kinds of changes would need to be made to the plugin code to make use of nested elements?
I was stumped on this myself, and I don't know if you still are, but for reference to others here's what I found.
You are right in assuming that the reader creates a separate table for it. Being that a DataSet can hold multiple tables, each "level" of elements gets its own table. However, any nested elements that have nested elements of their own will get their own table. Essentially, it keeps creating tables until it reaches the bottom of the xml tree. If an element has no children, it gets added as a cell in the data table.
In your case,
dataSet.Tables[0] will hold the top level nodes (all the <.profiles>). But since the nested element <.profile> has elements of its own, Tables[0] will likely only have one row. The next level deeper, dataSet.Tables[1] will hold all <-profile> nodes. Although since <.subsectors> has sub-element <.subsector>, it will not be in Tables[1], but rather in Tables[2] which goes yet level deeper.
I know it has been a while since this was asked, but hopefully this will be helpful.
I'm adding tree nodes to TreeView programmatically based on values from DB.
I need to add child nodes to those nodes before. The only way to locate them is by myReportsNode.ChildNodes[int index], but this information is useless for me, as I need to find them by their value, or some unique id.
FindNode is not a good option, as I don't know exactly where they are, and looking for each node via itarating through the tree is a waste. I though of a dictionary for nodes.
Any ideas?
You need to use a tree traversal. If there is some sort of ordering, you could make sure they are loaded into the tree reflecting that ordering, and you can use a depth-first search and have logarithmic complexity (every bit as efficient as a tree-based Dictionary). A dictionary of nodes would be a waste of memory, since you already have a tree structure you can use--that is, if there is some sort of ordering.
If you would give us some sort of idea of how the data is in the tree, I could help even more.
Use strategy of using three four columns in your database table.
1) nodeId
2) nodeText
3) nodeValue
4) parentId
When a node is clicked, send request via ajax to find if this id has child, if yes bring its childs and append below it. Else no child found, no need to append.
I'm struggling with this problem for quit a while.
This is what I want to do:
I want to build a query for the Windows Indexing Service that should look like this
SELECT ... FROM (TABLE Catalog1..Scope('Deep traversal of "Path1"','Deep traversal of "Path2"') UNION ALL TABLE Catalog2..Scope('Deep traversal of "Path3"')) WHERE ...
I get the information from a <asp:Listbox SelectionMode=multiple> (which has a file as data-source)
And it comes in the following way:
'DisplayNameInListbox1'=Catalog1#Path1;Path2&Catalog2
'DisplayNameInListbox2'=Catalog1#Path1
'DisplayNameInListbox3'=Catalog1#Path1;Path2&Catalog2#Path3
...
In one of the Listbox values can be multiple catalogs and multiple values can be selected.
Each catalog can stand alone or be restricted to specified paths(#path;path2)
My attempt:
I tried to store all the information in a Dictionary<string Catalog, List<string Paths>>
which works fine if I don't select two values which contain the same catalog name. I also can't just skip a catalog if I already have a key with that name because the path restrictions could be different.
Can anyone help me to find a good way solving this problem? (it would also be possible to change the way the data is stored - I just need to be able to provide it to the Listbox from a file)
Cheers
Here comes the solution to my problem:
I guess most of the time the simplest solution is the best!
I divided the problem in two parts. Now I first merge the catalogs and paths so every catalog exits only once in the dictionary.
And in the second step I can build the query sequentially :)