I am working on a basic MVC5 / EF6 application, and I run the following error when I try to raise the Read action in MVC:
Error
There was an error running the selected code generator:
'No Parameterless constructor defined for this object'
In any case, this is not necessary, because I am reading, not deleting or updating, but in the model in question there is no constructor without parameters (as for the models below).
public class Article
{
public int ArticleID { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public DateTime PublishDate { get; set; }
public virtual Author Author { get; set; }
public Article()
{
}
}
My controller is below, and it also has a parameterless constructor:
public ArticleController()
{
connection = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
context = new TRNContext(connection);
}
public ActionResult Index(int id)
{
return View(context.Articles.SingleOrDefault(a => a.ArticleID == id));
}
source
share