If you work with attached objects, EF will only generate updates for fields that have been changed. If you work with individual objects, you must manually tell EF what has changed. If you call this:
context.Entry(yourEntity).State = EntityState.Modified;
you tell EF that all properties must be changed. But if you call it:
context.Entry(youreEntity).Property(e => e.SomeProperty).IsModified = true;
You will say that only SomeProperty changed (only this property will be updated). I'm not sure that you can do the reverse operation by marking the entire object as modified and selecting properties that should not be changed, but you can check it yourself.
If your CreatedOn populated in a database, you can mark it as DatabaseGeneratedOption.Identity and it will never be modified by your application.
Ladislav Mrnka
source share