I’m creating a forum which have some what similar look as this!
A user can ask a Question and can get answer for that from other users.
I have two different table Question{id(pk), Question} and Answer{id(pk), ans, Qid(fk)}
Also i have created Controller for this
It contain Index,create,details
in side Index ,i have inserted as follows:
using (var _db = new Model1Container())
{
Question q = _db.Questions.Find(id);
return View(q);
}
inside the view i have a link called show which will show all the comments related to that particular question…..
but I’m not able to do this…i have tried:
using (var _db = new Model1Container())
{
var a = (from m in _db.Answers
where m.QuestionQId == id
select m);
return View(a);
}
but it is not working…i am using Entity framework
please help me out!!!
Change
To
using (var _db = new Model1Container()) { var a = (from m in _db.Answers where m.QuestionQId == id select m).ToList(); return View(a); }To force execution now. Otherwise execution of the query can happen outside the scope of your _db variable.