我正在开发一个MVC应用程序,已经完成了一部分(使用Entity Framework),并且运行良好。但是,现在出现了一个错误:
+ 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; }
}
我该如何解决这个问题?我认为我已经尝试了一切我能在这里找到的方法,但什么都没用。
此外,我已经从数据库中读取并使用了数据,并且它也起作用。只有在这种情况下失败了(至少到目前为止)。我对此感到非常困惑。