Thr*_*gic 10 entity-framework asp.net-mvc-5
我正在研究基本的MVC5/EF6应用程序,当我尝试在MVC中构建一个Read Action时遇到以下错误:
Error
There was an error running the selected code generator:
'No Parameterless constructor defined for this object'
Run Code Online (Sandbox Code Playgroud)
它不应该需要它,因为我调用的是读取而不是删除或更新,但是有问题的模型确实有一个无参数构造函数(就像下面的模型一样).
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()
{
}
}
Run Code Online (Sandbox Code Playgroud)
我的控制器在下面,它还有一个无参数构造函数:
public ArticleController()
{
connection = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
context = new TRNContext(connection);
}
// GET: Article
public ActionResult Index(int id)
{
return View(context.Articles.SingleOrDefault(a => a.ArticleID == id));
}
Run Code Online (Sandbox Code Playgroud)
Vec*_*ria 10
由于无法连接到数据库,我在ASP.NET Core MVC应用程序上遇到此错误.我花了几个小时检查我的模型和dbContext类只是为了意识到它们没有任何问题.该应用程序只是无法连接到数据库.我必须检查两个地方.
| 归档时间: |
|
| 查看次数: |
5630 次 |
| 最近记录: |