mardi 6 novembre 2018

Data repository pattern for complex objects

So I've inherited a system that implements a data repository pattern. In it's current state it takes a DTO object, strips it down to contain only the data that maps to the a table in sql server and then uses entity framework to do the commit.

Now there are a bunch of issues, but the first one I'd like to resolve is how to handle complex objects.

For instance. I have a Client object which contains a list of Contacts. Given that we are putting the domain logic behind a web service, the API accepts a single Create Client Request.

I would then like to handle that request by creating a client in the database and also the contacts that were sent along in the request as part of the Client DTO.

So my question is, in the data repository for ClientDataRepo.Create(ClientDto), can I put the logic that first writes the client data into the database and then have it call the ContactDataRepo.Create(listofContacts) from within the ClientDataRepo?

I'm not sure if the data repo Create method should only focus on creating a record in one table for a specific object or it it is acceptable for it to do several steps spanning several tables?

Aucun commentaire:

Enregistrer un commentaire