Elisabeth
Elisabeth

Reputation: 21206

Passing full entities to repository or just the ID`s to delete them?

I just asked myself is it really needed to pass the whole List SelectedCustomers to the delete method of the Repository like:

_customerRepo.DeleteCustomers(SelectedCustomers);

Would it not be better to pass just the Id`s of the customers to be deleted like

List<int> SelectedCustomerIDs = GetSelectedCustomersIDs(SelectedCustomers);
_customerRepo.DeleteCustomers(SelectedCustomerIDs);

I am not using an ORMapper which surely accepts only full entities to acceptchanges on or to remove it from the context.

I am using sqlite so I thought passing a List of int values is faster/less Ram than passing a List of entities.

What do you think?

Upvotes: 1

Views: 251

Answers (1)

Oded
Oded

Reputation: 498962

The objects are already in memory and you are not copying them when passing them to the repository, but only the references to them. So, you will not be saving on memory (unless your repository is on a different server).

So long as in your repository you are just using the IDs to pass to the database, you should be fine.

Upvotes: 1

Related Questions