I have an AlbumArtist class (which is my EF Entity):
public class AlbumArtist : IEquatable<AlbumArtist>
{
public int Id { get; set; }
public string Title { get; set; }
public virtual List<Album> Albums { get; set; }
public bool Equals(AlbumArtist albumArtist)
{
return Title.Equals(albumArtist.Title);
}
public override int GetHashCode()
{
return Title.GetHashCode();
}
}
And an Album class (which is my EF Entity too):
public class Album : IEquatable<Album>
{
public int Id { get; set; }
public string Title { get; set; }
public virtual List<AlbumArtist> AlbumArtists { get; set; }
public bool Equals(Album album)
{
return Title.Equals(album.Title);
}
public override int GetHashCode()
{
return Title.GetHashCode();
}
}
So, as you see, I have many-to-many relationship.
I create one list, populate it, than save it with DbContext, then I create and populate the second list. And then I try to merge that two lists (one from DbContext, second from the local variable) and save the result to DbContext as well (insert new entities and update existing).
I have the following data in my two lists:
--Infected Mushroom
----Classical Mushroom
----Converting Vegetarians
...
--Infected Mushroom
----The Gathering
----Converting Vegetarians
--Skazi
...
And I try to get the following data:
--Infected Mushroom
----Classical Mushroom
----The Gathering
----Converting Vegetarians
--Skazi
...
Please help me to write some LINQ query to achieve my goal.
Thanks!