How to remove CRUD operations from Entity Class

Posted by GlutVonSmark on Programmers See other posts from Programmers or by GlutVonSmark
Published on 2014-08-25T14:21:05Z Indexed on 2014/08/25 16:27 UTC
Read the original article Hit count: 1131

Trying to get my head around removing dataStore access from my entity classes.

Lets say I have an AccountsGroup entity class. I put the all DBAccess into AccountsGroupRepository class.

Now should I have a DeleteFromDB method in the AccountsGroup class, that will call the repository?

Public Sub DeleteFromDB
  dim repository as new AccountsGroupRepository(me)
  repository.DelteFromDB
End Sub

Or should I just always use repositry whenever I need to delete an entity, and not have the CRUD methods in the entity class?

What happens when there is some business logic validation that needs to be done before the delete can proceed. For example if AccountsGroup still has some Accounts in it the delete method should throw an exception. Where do I put that?

© Programmers or respective owner

Related posts about class-design

Related posts about vb.net