0

I am confused as to the actual usage of a DTO, and my confusion arises from the fact that most articles say that DTOs are to be used to read data from database and pass it to external clients and then these external clients will then choose to do what they want with it. So I want to know if it is recommended or not to insert Data into the database through DTOs.

I have created a dto that maps to the entity and also then created repository class that has the methods for saving data into the database through the dto, I then created my dtocontroller where I then implemented the actual saving and I was able to save the data into the database.

So my question is: Is it recommended to insert data into a database through a DTO or DTO is supposed to be read data from the Database only?

Obert
  • 3
  • 2

1 Answers1

0

DTOs are for passing data around, usually as a REST call payload or response (Controller). Also for passing/returning to Service methods. Entities are for persisting to the DB within a Repository.

Normally a Service calls the DTO/Entity mapping around calls a Repository, which only deals in Entities.

This answer probably explains better.

John Williams
  • 4,252
  • 2
  • 9
  • 18