Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Ok so i've got a flowchart system, with models of:

Question,End Result, Answer

A Question has:
ID
List<answer>
Value

Answer has:
ID
NextQuestionID
CurrentQuestionID
ResultID
Value

Result has:
ID
Value

Now some of the routes point to the same question (i.e 2 routes can point to question ID 2)

at the moment to load the question, when a answer is clicked it passes a nextQuestionId and this is used to load the question. Now the answers are then loaded by context.Answers(a=> a.CurrentQuestionId == currentQuestion.Id)

problem is with this, there could be 4-6answers against that questionID, but each answer will route to somewhere diffferent.

Can anyone think of a way to load the answers for that Question, without having to type in the question more than once and giving it a different ID?
Posted
Comments
CHill60 29-Jan-15 10:47am    
A link table containing PrevQuestionID, NextQuestionID or something similar - definitely do not load the Question more than once!
Grant Weatherston 29-Jan-15 10:52am    
i dont think this would work, as this would mean duplicate question records as the previous questionId will be different too
Sergey Alexandrovich Kryukov 29-Jan-15 10:55am    
No, just the opposite. It means that you can have each element of the graph only once in the whole database, and relations between table will make up whole flow graphs.
—SA
Sergey Alexandrovich Kryukov 29-Jan-15 10:52am    
You should design the whole model of the flow using holistic approach, solving not just the problem of storage of just one element, but everything. Flow chart is the general-shape graph, with each node and relation carrying its separate property set. You can used two approaches: 1) map your graph model to relational model of your database, 2) develop a separate document type (or use existing one) for the whole workflow and store these documents as whole independent element, not having relations between element of its content and other documents.
—SA
BillWoodruff 30-Jan-15 11:12am    
It seem to me your architecture is a bit over-elaborated, why should an instance of a Question need to know the next Question ?

Why not have something like:

1. Table with all possible Answers, each with a unique ID.

2. Table of Questions where each Question has a List of ID's of possible answers, and an ID of the correct answer.

3. A QuestionManager (controller) that "does the right thing" to present a view(s), keeps track of total results, the current Question and whether the answer was correct, manages transition to the next Question, etc.

1 solution

Essentially you are trying to store a tree-structure.

Have a look at these CP articles

General trees persisted in relational databases[^]

Trees in SQL databases[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900