locked
Create a Many-to-Many Relationship RRS feed

  • Question

  • I followed this article How to create Many to many Relationship (Andy Kung) but got some errors:

    1) Movie: The referenced Movie is either not set or no longer exists.

    2) Genre: The referenced Genre is either not set or no longer exists.

    Some people solved these errors by this code:

    MovieGenre mg = this.MovieGenreCollection.AddNew();

    mg.Movie = this.MovieProperty;

    mg.Genre = this.GenreCollection.SelectedItem;

    But when I wrote tis code in LS, there isn't anything like "MovieGenreCollection" or "GenreCollection". I don't know whyy???

    Anyone help me?


    • Edited by Little_1991 Monday, December 26, 2011 11:16 PM
    Monday, December 26, 2011 4:45 PM

Answers

  • Hi

    When you create record by code you need to use something like this:

    Entity varEntity = this.EntitySet.AddNew()

    so, in general, if entity name is MovieGenre then you should change:

    Entity = MovieGenre

    EntitySet = MovieGenres (see what's the plural name of your entity in Entity Designer).

    I would change MovieGenreCollection to MovieGenres and GenreCollection to Genres (of course, if your entities are MovieGenre and Genre).

    Best regards


    Spaso Lazarevic
    • Marked as answer by Little_1991 Monday, December 26, 2011 11:16 PM
    Monday, December 26, 2011 5:46 PM