【发布时间】:2016-12-26 22:20:07
【问题描述】:
我正在做我的 MVC 应用程序,我已经完成了其中的一部分(使用实体框架)并且工作正常。但是,不,我得到了一个错误:
+ InnerException {"The class 'ClassDeclarationsThsesis.Models.Subject' has no parameterless constructor."} System.Exception {System.InvalidOperationException}
An exception of type 'System.Reflection.TargetInvocationException' occurred in EntityFramework.SqlServer.dll but was not handled in user code
我的班级是这样的:
public partial class Subject
{
private int v;
private int userid;
public Subject(int v, int userid, string name)
{
this.class_id = v;
this.user_id = userid;
this.name = name;
}
public int class_id { get; set; }
public int user_id { get; set; }
public string name { get; set; }
public virtual Group Group { get; set; }
public virtual Subjects_Users Subjects_Users { get; set; }
public virtual Task Task { get; set; }
}
我该如何解决这个问题?我想我已经尽我所能尝试了一切,我在这里找到了,但没有任何效果。
此外,我已经从数据库中读取数据并使用它并且它可以工作。它只在这种情况下失败了(至少到目前为止)。我真的很困惑。
【问题讨论】:
-
您能否显示导致此错误的 linq 查询?您可能会重写它以使用当前类。
标签: c# asp.net .net entity-framework