以下引发异常。
传递给InsertOnSubmit的 course 对象是由Linq生成的Course类型。
public ActionResult Course(CourseViewModel c)
{
Course course = (Course) c; //CourseViewModel is derrived from Course
SchedulerDataContext db = new SchedulerDataContext();
db.Courses.InsertOnSubmit(course); // <- this is where exception is thrown
db.SubmitChanges();
}
答案 0 :(得分:1)
在尝试插入之前,您需要创建Course对象。
Course course = new Course { ... set the properties .. };
SchedulerDataContext db = new SchedulerDataContext();
db.Courses.InsertOnSubmit(course);
db.SubmitChanges();