Entity framework performing an Insert, when it should be doing an Update -
I am having a real problem with EF v1. 50 units have probably been mapped to me, but this one unit is creating sorrow for me.
This unit has mapping with other organizations, which are reference tables, but for some reason it is trying to add one or update it.
Here is a piece of my code:
using (var context = new someEntities ()) {var studentCourseJoin = context StudentCourseJoinSet.Where (o = & gt; ; O.Code == scjCode). first (); StudentCourseJoin.EntryStatus = New Entrepreneur {code = viewsModel. Student details. Interstitials code}; StudentCourseJoin.ParentalInHigherEducation = New ParentalInHigherEducation {Code = View Model Student Details ParentalInHigherEducationCode}; StudentCourseJoin.School = New School {Code = View Model Student Details School code}; StudentCourseJoin.Institution = New Institute {Code = View Model Student details. Institution code}; StudentCourseJoin.LastSchoolEndYear = ViewModel. Last Education Method; StudentCourseJoin.LastInstitutionEndYear = View Model. Student details. Final Institutions & Eyewear; // Student is trying to join a Kaiser Join. // But if I removed it, then it will fly over each other. Sacch Changes (right); }
If anyone has any ideas, then they will be very helpful.
Try adding those lines before calling SaveChanges
:
Item Position Entry Entry = Reference ObjectState Manager. GetObjectStateEntry (studentCourseJoin); Entry.ChangeState (EntityState.Modified);
Update:
Try instead for organization
:
< Code> StudentCourseJoin.Institution = context.Institutions.FirstOrDefault (i = & gt; i.Code ==Model.Student Details.Institution Code);
Comments
Post a Comment