I have the following classes.
namespace SmartAdminMvc.Models
{
[Table("vwFeedback")]
public class Feedback
{ [Key]
public int ProjectID { get; set; }
public int FeedbackNo { get; set; }
public int CustomerPersonNo { get; set; }
public int QuestionSeq { get; set; }
public int QuestionID { get; set; }
public int Applicable { get; set; }
public string Answer { get; set; }
public string AnswerText { get; set; }
public string Question { get; set; }
public string QuestionAlt1 { get; set; }
public string QuestionAlt2 { get; set; }
public string AnsType { get; set; }
public string Option1 { get; set; }
public string Option2 { get; set; }
public string Option3 { get; set; }
public string Option4 { get; set; }
public string Option5 { get; set; }
}
}
namespace SmartAdminMvc.Models
{
public class FeedbackContext : DbContext
{
public DbSet<Feedback> Feedbacks { get; set; }
}
}
Following is my controller class
namespace SmartAdminMvc.Controllers
{
public class FeedbackController : Controller
{
// GET: Feedback
public ActionResult Index()
{
FeedbackContext feedbckContxt = new FeedbackContext();
List<Feedback> allFeedbcks = feedbckContxt.Feedbacks.ToList();
try{
foreach (var item in allFeedbcks)
{
System.Diagnostics.Debug.WriteLine("Answer " + item.Answer + " Question Id. " + item.QuestionID + " CustomerPersonNo " + item.CustomerPersonNo);
}
} catch(Exception exp){
Response.Write("Error:" + exp.ToString());
}
return View(allFeedbcks);
}
}
}
Following is shown as the output
Answer 4 Question Id. 1009 CustomerPersonNo 10002
Answer 4 Question Id. 1009 CustomerPersonNo 10002
Answer 4 Question Id. 1009 CustomerPersonNo 10002
Answer 4 Question Id. 1009 CustomerPersonNo 10002
Answer 4 Question Id. 1009 CustomerPersonNo 10002
Answer 4 Question Id. 1009 CustomerPersonNo 10002
Answer 4 Question Id. 1009 CustomerPersonNo 10002
Answer 4 Question Id. 1009 CustomerPersonNo 10002
Answer 4 Question Id. 1009 CustomerPersonNo 10002
Answer 4 Question Id. 1009 CustomerPersonNo 10002
On the Output it prints only the first row values (repeatedly) from the table. But the number of rows fetched is correct.
I have been struggling with this issue for very long . It will be a great help if someone could help me out.
Thanks