Add existing object to list

Viewed 1145

I have an Order class which contains a List<Album> property. In initialization I have a list of Albums:

var albums = new List<Album>
{
    new Album { ArtistId = 2, GenreId = 2, Price = 9.99m, Title = "Mine is Yours" },
    new Album { ArtistId = 2, GenreId = 2, Price = 9.99m, Title = "Robbers & Cowards" },
    new Album { ArtistId = 2, GenreId = 2, Price = 9.99m, Title = "Hold My Home" }
};

Next I have a list of Orders:

var orders = new List<Orders>
{
    new Orders { Albums = //code}
};

What I want to do is be able to add albums from the albums list to the Albums property. Essentially I don't want to be writing Albums = {new Album{//code},{//more code}}. I want to write something like Albums = {{AlbumId = 1}, {AlbumId = 2}}. Etc to add existing albums to the list.

Apologies if badly worded.

2 Answers
Related