I have three tables in my database. Every table works with different Entity Class, the code:
public class Quizs
{
[Key]
public int QuizId { get; set; }
public string Title { get; set; }
public string Instructions { get; set; }
public string IsTimerEnabled { get; set; }
public virtual ICollection<Question> Questions { get; set; }
}
public class Question
{
[Key]
public int QuestionId { get; set; }
public virtual ICollection<Answers> Answers { get; set; }
public int RightAnswer { get; set; } // Key of Answers[]
public int QuestionType { get; set; } // 1 = One choise, 2 = Multiple Choise
public string Explantion { get; set; } // To appear after answering the question
public int MaxTime { get; set; } // In seconds
}
public class Answers
{
[Key]
public int asId { get; set; }
public int Id { get; set; }
public string Text { get; set; }
}
So now i need to output all the data in this three tables to the WebApi page.
Here is the code that pulling out the data in the controller:
// GET api/QuizsData/
public IEnumerable<Quizs> Get()
{
return dba.Quiz.Include("Questions").Include("Questions.Answers").ToList();
}
This is what I get when I go to the route of the api:
{"Message":"An error has occurred.","ExceptionMessage":"Invalid column name 'Question_QuestionId'.\r\nInvalid column name 'Question_QuestionId'.","ExceptionType":"System.Data.SqlClient.SqlException","StackTrace":" at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction)\r\n at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction)\r\n
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)\r\n
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)\r\n at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()\r\n at System.Data.SqlClient.SqlDataReader.get_MetaData()\r\n at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)\r\n at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite)\r\n at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)\r\n at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)\r\n at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)\r\n at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)\r\n at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)\r\n at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)"}
I got this Exception Message.. any help?
Thanks!
Quizs
to have only one question? – Theodoros Chatzigiannakis