Hi,
Please correct me if my understanding is wrong...
If you say that the foreach loop is run twice, I am assuming that the splittedId List<string> object contains 2 values which are distinct in value.
Inside the foreach loop, you are getting a distinct customer by id, and the dataModel object you assign this customer to, is a different reference each time the loop runs. You have not overwritten the data in DtoList from the first loop run, you just have different instances of dataModel in each loop run which contains its own DtoList.
If you want to append the data to a common list for each loop run, create a common DtoList outside the loop and append to this for each dataModel within the loop. Please see this coding ground example I created, simulating your expected behaviour (You can execute the code in the coding ground and see the appended values printed out):
Coding Ground Example[
^]
Regards,
Mark.