The warning not to do that is there to discourage people to go that route to set entity field values in normal code.
I don't consider migration code from one object paradigm (DTO) to another (Entity/business objects) every day code: it's special code to get a given specialistic task done.
If you keep the DBValue around in your DTO as well, you have to fill the entity as if it was read from the DB, and then set the values. You can make this easier, by doing this:
- create new entity instance
- set entity.IsNew to false
- use field.ForcedCurrentValueWrite(DBValue, DBValue); This will make the entity look like as if it's fetched from the db.
- use entity.SetNewFieldValue(fieldName, newCurrentvalue);
this will make a field which changed indeed be marked changed and an entity dirty. If not, nothing will change. So you don't have to check whether DBValue or CurrentValue are different to set IsChanged, that's been taken care of.
I think this will solve your concern. Indeed it is a bit low-level to go this route, but as you want to re-build an entity instance in memory without going to the db, you actually have to, the only code which does the same thing is the fetch logic which fetches data from the db