Why is EF Core not updating a column in the database when entity is attached and ChangeTracker shows the change

21 Views Asked by At

I updated three properties of an entity. The ChangeTracker.DebugView corectly shows the entity as Modified as well as the three properties that I changed as modified.

When I call DbContext.SaveChanges() two of the modified properties get correctly updated to the database, but one property Notes does not get updated.

Note: The property on the class does NOT have the attribute [NotMapped].

I ran the SQL Profiler to inspect the calls to the database and the UPDATE statement shows all modified columns except Notes, which explains why it did not get updated to the database.

Why is the property getting omitted from the UPDATE statement, when the ChangeTracker correctly sees the property/column as modified?

See below from ChangeTracker.DebugView:

MyEntity {ID: 1} Modified
  ID: 1 PK
  SampleGuid: '72A2DFAA-0EB9-4408-AF68-BBE0294C3179' Modified Originally <null>
  ParentID: 1 FK
  Notes: 'Here are some notes...' Originally <null>
  LastUpdatedTime: <null>
  Status: 2 Modified Originally 1

SQL Profiler - Notes missing from UPDATE statement:

UPDATE [dbo].[MyEntity] SET [SampleGuid] = @p0, [Status] = @p1
OUTPUT 1
WHERE [ID] = @p2;
0

There are 0 best solutions below