I am making an MVC 3 web application and have a weird problem. Here is the code:
Model Announcement:
public class Project
{
public int ID { get; set; }
[Required(ErrorMessage = "Write a title.")]
public string Title { get; set; }
public DateTime TimeAdded { get; set; }
[Required(ErrorMessage = "Write some description.")]
[MaxLength(int.MaxValue)]
public string Content { get; set; }
public ICollection<Comment> Comments { get; set; }
}
public class Comment
{
public int ID { get; set; }
[Required()]
public int ProjectID { get; set; }
public DateTime TimeAdded { get; set; }
[Required()]
public string Text { get; set; }
public Project project { get; set; }
}
Controller:
public class HomeController : Controller
{
dataDBContext db = new dataDBContext();
public ActionResult Index()
{
var comments = from c in db.Comments
select c;
var projects = from p in db.Projects
orderby p.TimeAdded descending
select p;
return View(projects.ToList());
}
?
:
public class HomeController : Controller
{
dataDBContext db;
public HomeController()
{
db = new dataDBContext();
db.Configuration.LazyLoadingEnabled = false;
}
public ActionResult Index()
{
var projects = from p in db.Projects
orderby p.TimeAdded descending
select p;
return View(projects.ToList());
}
. LazyLoadingEnabled. project.ToList(), .
- :
public class HomeController : Controller
{
dataDBContext db;
public HomeController()
{
db = new dataDBContext();
}
public ActionResult Index()
{
var projects = from p in db.Projects
orderby p.TimeAdded descending
select p;
var comments = from c in db.Comments
select c;
List<Comment> l = comments.ToList();
return View(projects.ToList());
}
. ToList() . , . , , ( 3). ?