Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6081507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:11:00+00:00 2026-05-23T11:11:00+00:00

I have the following domain model: public class Playlist { public long Id {

  • 0

I have the following domain model:

public class Playlist
{
    public long Id { get; set; }
    public string Title { get; set; }
    public virtual ICollection<Song> Songs { get; set; }
}

public class Song
{
    public long Id { get; set; }
    public string Name { get; set; }
    public virtual Playlist Playlist { get; set; }
    public virtual ICollection<Catalog> Matches { get; set; }
}

public class Catalog
{
    public long Id { get; set; }
    public string Title { get; set; }
}

My service has the following code:

public PlaylistResult FindByPlaylistId(long id)
{
    Playlist playlist = playlistRepository.GetById(id);

    foreach (var song in playlist.Songs)
    {
        song.Matches = catalogRepository.GetMatches(song.Name).ToList();
    }

    return new PlaylistResult(new PlaylistDTO(playlist), playlist.Songs.Select(x => new SongDTO(x)));
}

My service gets a playlist and songs from the database and then for each song in the playlist it fires a query to get additional matches from the database (using SQL Server full text search) specific to that song.

The data is then converted into DTO’s, added to a result object and passed back to the controller. The code looks like:

public class PlaylistResult
{
    public PlaylistResult(PlaylistDTO playlist, IEnumerable<SongDTO> songs)
    {
        Playlist = playlist;
        Songs = songs;
    }

    public PlaylistDTO Playlist { get; private set; }

    public IEnumerable<SongDTO> Songs { get; private set; }
}

The problem:

The PlaylistResult object has worked great so far but the recent introduction of matches has made things a bit more complicated. It looks like I have no other choice than to modify my SongDTO to take into account matches and look like this:

public class SongDTO
{
    public SongDTO(Song song, IEnumerable<CatalogDTO> matches)
    {
        Id = song.Id;
        Name = song.Name;
        Matches = matches;
    }

    public long Id { get; private set; }

    public string Name { get; private set; }

    public IEnumerable<CatalogDTO> Matches { get; private set; }
}

But doesn’t this violate the purpose of DTO’s? It is my understanding that DTOs are a flattened representation of data and this approach is not flattened. On the other hand, I don’t see how else to do this since each match is specific to each song.

I am aware that I could make this easier on myself and throw out the DTO’s and pass the domain model to the controller directly and call it a day. But I don’t want to do that since the whole purpose is to learn how to work with DTO’s.

Any input is greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:11:00+00:00Added an answer on May 23, 2026 at 11:11 am

    DTO’s are not a flattened representation of data although they can be.

    That’s the beauty of them – you can structure them as you need to, as opposed to how the database defines things. Also they are a means of separating out data from behaviour.

    I wouldn’t put a reference to the Domain object within the DTO at all. (You have it in the constructor) Use a factory to build the DTO’s so your clients only need reference the DTO’s and not the Domain objects.

     Song mySong;
     SongDTO = DTOFactory.GetSong(mySong);
    

    If your clients need to reference the Domain objects, then they may as well use them!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following domain model: public class Campaign { public virtual long Id
I have the following domain model: public class Name { private readonly string fullName;
I have the following domain: public class FileInformation { public String FileName; public String
Given domain model... public class Entity { public int Id { get; set; }
I have the following domain model setup using EF code first: public class User
I have the following Model Trip Model // think of Grails domain class public
I have the following domain objects: public class UserSpecialization : PersonSpecialization, IUserSpecialization { public
I have the following Grails domain class: class Product { String name Float basePrice
I have added the following method in my User Domain class String getNameAttribute(){ return
I have a domain data model which returns a class such as the following:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.