linq怎么给外键赋值呢?
QuestionsLibraryEntities ques = new QuestionsLibraryEntities();
Csw_ExaminationPaper paper = new Csw_ExaminationPaper(); paper.Csw_ExaminationPaperType.Ept_Code = int.Parse(Ept_Code);//这行代码报未将对象引用设置到对象的实例,就是说paper.Csw_ExaminationPaperType为null
//paper.Csw_ExaminationPaperType.Ept_Code = int.Parse(Ept_Code);
paper.Subject_Id = int.Parse(Subject_Id);
paper.Grade_Id = int.Parse(Grade_Id);
paper.EP_Title = EP_Title;
paper.EP_Count = int.Parse(EP_Count);
paper.EP_Author = EP_Author;
paper.EP_CreateTime = DateTime.Now;
paper.EP_LastUpdateTime = DateTime.Now;
paper.EP_ExamTime = int.Parse(EP_ExamTime);
paper.EP_TotalPoints = int.Parse(EP_TotalPoints);
paper.EP_Status = int.Parse(EP_Status);
paper.EP_CreatorID = EP_CreatorID;
paper.EP_TestCount = EP_TestCount;
paper.EP_IsGenerate = EP_IsGenerate;
ques.AddToCsw_ExaminationPaper(paper);
ques.SaveChanges();
context.Response.Write(paper.EP_Code.ToString());
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4605/viewspace-3133599/ ,如需转载,请注明出处,否则将追究法律责任。