Reputation: 520
Here's my problem: I have 3 tables in my database
Movies (list of movies)
Genres (table with all possible genres)
RelatedGenres (those genres that belog to a specific movie and point a specific genre, since movie can have more than 1 genre)
The relationships are as folows:
Movies.ID -> RelatedGenres.MovieID -> Genres.ID
I have a model with assosiations (navigation properties). What I get:
class Movie
{
public int ID { get; set; }
public string OriginalTitle { get; set; }
public ObjectCollection<RelatedGenre> RelatedGenres { get; set; }
}
where
class RelatedGenre
{
public int ID { get; set; }
public int MovieID { get; set; }
public ObjectCollection<Genre> Genres { get; set; }
}
What I want:
class Movie
{
public int ID { get; set; }
public string OriginalTitle { get; set; }
public ObjectCollection<Genre> Genres { get; set; }
}
As you can see, i want to skip data from this array of RelatedGenres & just get array of concrete Genres...
How can I achive this? Thanks in advance =)
Upvotes: 0
Views: 1784
Reputation: 32437
You need to remove th ID
column of the RelatedGenres
table. The join table of many-to-many relationship should only contain the keys of the participating entities.
EF will automatically model the relationship as you have shown in the final code sample.
Upvotes: 5