I don't know about OpenAccess but I think roughly the same principles apply as entity framework. From that background I only see major issues with your code.
The first objection is from an architectural point of view. Your entity object is not supposed to know about the existence of a context.
Other objections are technical.
As you already pointed out your code will be executed each time
SystemUsers
is addressed. TheToList()
will always cause a database hit. I'm not sure what happens if you remove theToList()
, that depends on whatGetChanges
andGetDeletes
do. I don't know. But at the very least it would cause an additional database hit each timeSystemUsers
is enumerated.I assume that, like EF, OpenAccess also supports lazy loading of collections that are marked
virtual
. Probably it creates a proxy type that is derived from the entity type and that adds wiring to navigation properties in order to implement lazy loading. As the property only has a getter I assume that OpenAccess populates a collection byAdd
ing items to it. This causes all kinds of side effects:- It would mean that the base property is accessed (running the query) each time an item is added to it.
- Your code returns a temporary list. Any added item will be gone next time you address the property!! The collection will never get populated.
Finally it may cause unpredictable behaviour when a second reader is opened while your object is being materialized.
So I think you should solve the problem of soft deletes by a repository that returns entities with or without the ones that are marked for delete. Or maybe you can create a calculated (unmapped) property that returns the SystemUsers without the "deleted" ones.