LINQ to SQL on Windows Phone 7.5: Listing 2.

The Review table.

[Table]
public class Review : INotifyPropertyChanging {
  private string comment;
  private int movieId;
  private EntityRef<Movie> movie;

  [Column(IsPrimaryKey = true,
    IsDbGenerated = true,
    DbType = "INT NOT NULL Identity",
    CanBeNull = false,
    AutoSync = AutoSync.OnInsert)]
  public int ReviewId { get; set; }


  [Column]
  public string Comment {
    get { return comment; }
    set {
      if (comment == value) return;
      comment = value;
      NotifyPropertyChanging("Comment");
    }
  }

  [Column]
  public int MovieId {
    get { return movieId; }
    set {
      if (movieId == value) return;
      movieId = value;
      NotifyPropertyChanging("MovieId");
    }
  }

  [Association(Storage = "movie", ThisKey = "MovieId", OtherKey = 
    "MovieId", IsForeignKey = true)]
  public Movie Movie {
    get { return movie.Entity; }
    set {
      Movie previousValue = this.movie.Entity;
      if (((previousValue != value)
          || (movie.HasLoadedOrAssignedValue == false))) {
          NotifyPropertyChanging("Movie");
          if ((previousValue != null)) {
            movie.Entity = null;
            previousValue.Reviews.Remove(this);
          }
          movie.Entity = value;
          if ((value != null)) {
            value.Reviews.Add(this);
            movieId = value.MovieId;
          }
          else {
            movieId = default(int);
          }
      }
    }
  }

  public event PropertyChangingEventHandler PropertyChanging;
  private void NotifyPropertyChanging(string propertyName) {
    if (PropertyChanging != null) {
      PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
    }
  }
}

About the Author

Nick Randolph runs Built to Roam, a consulting company that specializes in training, mentoring and assisting other companies build mobile applications. With a heritage in rich client applications for both the desktop and a variety of mobile platforms, Nick currently presents, writes and educates on the Windows Phone platform.

comments powered by Disqus

Featured

Subscribe on YouTube