I found multiple posts for this issue, however my issue is little different and error shown is exactly matches to my scenario.
I have two different schema under by database. e.g.
PreSchool.Students
&School.Students
. And per our requirements, rest is same for bothStudents
tables, including primary key.Now in my code, I am updating record of 'PreSchool.Students' using following code:
var wouldBeUpdatedStudent = await context.Students .FindAsync(student.StudentIdentity).ConfigureAwait(false); wouldBeUpdatedStudent = student; //updated student object context.Entry(wouldBeUpdatedStudent).State = EntityState.Modified; // This line throws error var result = await context.SaveChangesAsync().ConfigureAwait(false);
Under
OnModelCreating
I clearly settableName
&SchemaName
for each of Entity. By this, I am expecting whenever I change entity/ model state, it should catch the correct table as per setting done underOnModelCreating
. However this is not happening and throws exception.
I tried using
context.Students.AsNoTracking()
this works if no cascading to Students Entity. However, there are some cascading/children entities which are also same DDL. e.g.context.Student.Exams