Using .NET ASPNET WebApi.
I have a simple model. A Song and an Artisk, where a song can have multiple Artists and an Artist can be related to many Songs – a Many-To-Many relation ship.
public class Artist
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime? Born { get; set; }
}
public class Song
{
public int Id { get; set; }
public string Name { get; set; }
public DateTime ReleaseDate { get; set; }
public Genre? Genre { get; set; }
public ICollection<SongArtist> Artists { get; set; }
}
public class SongArtist
{
public int Id { get; set; }
public Song Song { get; set; }
public Artist Artist { get; set; }
}
I am building an API op the model, and I was wondering how the best way to handle POST. Obviously I need to add multiple Artists when creating a Song. I can see 3 possible solutions:
-
I am using DTO objects, show I just add a list on the ArtistDTO. Something like this:
public class SongDto { public int Id { get; set; } [Required] [MinLength(2)] public string Name { get; set; } [Required] public DateTime ReleaseDate { get; set; } public ICollection<ArtistDto> Artists { get; set; } }
And then provide it in body.
-
Read a array of IDs from the query
-
Seperate endpoint to add and delete artists on a song?
Tried to find information on the topic without luck.