score:3
1:) Hierarchical data should not be displayed in a <table>
, use nested <ul>
or <ol>
instead. Tables are for tabular data.
2:) Since c# is an object oriented language, I would not reference the objects in the tree by an Id. Why not add a collection of child objects as a member a sample code pattern would be:
class TreeElement
{
public TreeElement Parent {get;}
public IEnumerable<TreeElement> Children{get;};
public AddChild(TreeElement element }
public bool IsRoot { return Parent == null; }
public bool IsLeaf { return Children.Length == 0; }
public bool IsBranch {return !IsRoot && !IsLeaf; }
}
normally in a tree you don't want to do a parent lookup. So if not needed leave all the parent references to avoid useless complexity ;) Try to insert stuff in the database in an object structure like above.
3:) Key lookup according to your model will go eventually very slow in SQL. You 'll have to loop trough data and use if/else statements in your query On SQLTeam is a great sample on how to make that very fast with the use of an extra lineage column.
4:) Use linq to query and generate the results for your data.
score:0
I would suggest having the following tables:
Person
- Person_ID (PK)
- Type (student/teacher etc)
- Name etc...
PersonGroups
- PersonGroup_ID (PK)
- Description etc..
Subjects
- Subject_ID (PK)
- Description etc...
Classes
- Class_ID (PK)
- Subject_ID (FK)
- Description etc...
PersonClassMembership
- Person_ID (FK)
- PersonGroup_ID (FK)
- Class_ID (FK)
PersonGroupMembership
- PersonGroup_ID (FK)
- Person_ID (FK)
With this it is flexible enough to add more memberships such as new teachers or students to a class/group.
This is by no means the best way to do it or the 'right' way, its simply to get you going and thinking about normalising the database to make creating queries that give you the results more easily.
score:0
I don't agree with your table design. Putting mixed data in one table with recursion is really a bad idea. Don't do this unless you need to store tree-like data in DB. According to your question, a better design:
- table Students
- table Teachers
- table Classes
- table SubjectTypes(type_id,description) English,math,sports,etc...
- table Subjects(class_id,teacher_id,subject_type_id)
- table StudentDistribution(stu_id,subject_id)
- table Score(stu_id,subject_id,score)
score:1
If you can use Jquery in your application, then consider using the following Jquery plugin, which has got lot of features..
JsTree is absolutely free (licensed same as jQuery – under the terms of either the MIT License or the GNU General Public License (GPL) Version 2) - As stated in the jstree website.
Source: stackoverflow.com
Related Query
- Display data in hierarchical order using LINQ
- Display hierarchical data in C#
- c# Linq or code to extract groups from a single list of source data
- How to use pagelist with data source as multiple tables, to display table values in mvc?
- The data source does not support server-side data paging
- I am wondering about the state of connection and impact on code performance by 'yield' while iterating over data reader object
- How to search Hierarchical Data with Linq
- Hierarchical data in Linq - options and performance
- System.ArgumentException: Complex DataBinding accepts as a data source either an IList or an IListSource
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- How to get depth of hierarchical data with linq query?
- How does linq actually execute the code to retrieve data from the data source?
- LINQ Source Code Available
- Converting datatable into hierarchical data structure (JSON) using C#
- How can I query this hierarchical data using LINQ?
- Filling a hierarchical class structure with data
- .NET 4 Code Contracts: "requires unproven: source != null"
- Sum of hierarchical data using LINQ?
- Is there a way to speed up this code that finds data changes in two XML files?
- The given value of type String from the data source cannot be converted to type int of the specified target column
- Converting flattened hierarchical data from SQL Server into a structured JSON object with C#/Linq
- Merge duplicate data without affecting others in LINQ code
- Converting flattened hierarchical data into a tree structured JSON
- Advanced LINQ Grouping and Projection Query for Hierarchical Data (EF 4.0 + LINQ + ASP.NET MVC + HighCharts)
- C# LINQ Orderby on parent only in hierarchical parent-child relationship data
- How do I write a LINQ query that inverts the grouping of a hierarchical data source?
- Use a linq query as microsoft local report Data Source (WinForms)
- How to convert hierarchical data from a DataTable to JSON
- At what point is a LINQ data source determined?
- Display data tables grouped and separated by headings on an MVC view
More Query from same tag
- Use LINQ expression to Update Property of object
- Unable to cast object of type 'System.DBNull' to type 'System.String' On getting all Products
- linq where clause causes exception
- Convert Over Partition to LINQ
- LINQ to SQL LEFT JOIN, GROUP BY, COUNT, MAX and subquery
- Debug error message please. DbArithmeticExpression Arguements must have a numeric common type
- Most Efficient Many-To-Many Linq Query
- ORDER BY ASCENDING or NOT seems to it doesn't do anything
- Filter a LINQ query
- query cannot be enumerated more than once
- What is the best way to optimize or "tune" LINQ expressions?
- Using Linq, how can I obtain a list of column names from a GridView? From a DataTable?
- Linq To DataSet getting error
- Inner join two lists based on a child list
- Find hourly gaps in date ranges .NET
- DataTable select help
- Iterate custom class, Read Table
- C#: How to manipulate List<String> using LINQ or LAMBDA expression
- Dynamic query expression builder
- return column values as IEnumerable
- Use LINQ to compare List in C#
- Linq Where not filtering values
- Cannot insert the value NULL into column ... Exception issues
- Simple XML parsing throws Object reference error
- How use lambda expression in Distinct
- C#, Winforms & LINQ to SQL.. Datacontext lifecycle?
- lambda expression with nullable value - always false since the value of type Guid is never equal to 'null'
- Sort list based on another?
- How to create multiple nested conditions against joined tables in linq to entities?
- Linq select many into new column