Puser wrote:
I understand. Setting to null was only an example, a try, if another more easy way can be achieved then nice.
I have multiple scenarios where the notes field is linked to a (sub)collection like Order-OrderItem-SomeMemo. In these cases deletion/removal of an OrderItem is tracked, but on existing OrderItems with the memo field where someone wants to clear some, it cannot be done without also calling into the DataScope.
Maybe with some method like OrderItem.SomeMemo.Remove() or Clear() you could take care of that in the datascope also?
Ok, but what does 'Remove' mean in this case? Mark for delete? Remove from the graph? Delete immediately? That's a bit unclear. Adapter is designed around the idea that you give it commands to do things, either through a Unit of work or through the adapter. So there's no DB activity code in the entities. Also, there's no reference to the scope in the entity, so if there's a method in the entity, how does it get to the scope?
PS: For your information, I use automapper to map from dto to entity, and have created this with a custom llblgen template. But this is the only thing that would force me to call into the datascope , the rest is as simple as calling:
_mapper.Map(dto, entity);
At the moment that's the only way. The main problem for you is that the context used by the scope is internal. So even though you can for instance add a 'Remove()' method to a partial class of CommonEntityBase(), and obtain the Context (which is of type DataScopeContext in this case) of the entity there, you can't call the AddForDelete() of the DataScopeContext as it's internal. So adding this method yourself would solve your problem but it isn't going to work at the moment due to the nature of the context class...
I don't want to make it public as it's not a type that's to be used as a public type (as it then might be used as a Context which shouldn't be done).
I'll ponder a bit about this, adding a protected method perhaps to EntityBase/EntityBase2 which adds it to an active context for deletion if the context is a scope context. That won't help you today, but perhaps in the future.