The actions you want to do are meant for updating an existing entity without fetching it first. Otherwise a normal fetch, property set, save action would suffice, which doesn't require fiddling with state flags. Is this what you want to do, updating without fetching it first?
To make the runtime believe the entity is actually 'fetched' and not 'new', some things have to be done, which unfortunately mean, the entity is indeed fetched, the values in it are the ones set and it should persist these values as if you modified data from the DB. This means that
- the entity flag for 'new', IsNew, has to be set to false
- the Fields.State property has to be set to 'Fetched'
- you have to set a field's value to the value you want to set it to.
- the IsChanged flag for a field has to be set to true.
the last two are required because if you set a field to 'null' it doesn't change, its initial value is 'null' so it will be ignored.
this is rather verbose code, true. If you need this alot, you could opt for creating a small method / extension method, to do this for you.
Keep in mind that in v4 we optimized field value storage a lot, so setting the field value and setting the change flag is done now on the Fields object (entity.Fields.SetIsChanged(index, bool), entity.Fields.SetCurrentValue(index, value))