#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.1433
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;



[System.Data.Linq.Mapping.DatabaseAttribute(Name="Movies")]
public partial class MoviesDataContext : System.Data.Linq.DataContext
{
	
	private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
	
  #region Extensibility Method Definitions
  partial void OnCreated();
  partial void InsertMovie(Movie instance);
  partial void UpdateMovie(Movie instance);
  partial void DeleteMovie(Movie instance);
  partial void InsertGenre(Genre instance);
  partial void UpdateGenre(Genre instance);
  partial void DeleteGenre(Genre instance);
  #endregion
	
	public MoviesDataContext() : 
			base(global::System.Configuration.ConfigurationManager.ConnectionStrings["MoviesConnectionString"].ConnectionString, mappingSource)
	{
		OnCreated();
	}
	
	public MoviesDataContext(string connection) : 
			base(connection, mappingSource)
	{
		OnCreated();
	}
	
	public MoviesDataContext(System.Data.IDbConnection connection) : 
			base(connection, mappingSource)
	{
		OnCreated();
	}
	
	public MoviesDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) : 
			base(connection, mappingSource)
	{
		OnCreated();
	}
	
	public MoviesDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) : 
			base(connection, mappingSource)
	{
		OnCreated();
	}
	
	public System.Data.Linq.Table<Movie> Movies
	{
		get
		{
			return this.GetTable<Movie>();
		}
	}
	
	public System.Data.Linq.Table<Genre> Genres
	{
		get
		{
			return this.GetTable<Genre>();
		}
	}
	
	public System.Data.Linq.Table<AllMovies> AllMovies
	{
		get
		{
			return this.GetTable<AllMovies>();
		}
	}
	
	[Function(Name="dbo.GetGenre")]
	public ISingleResult<Genre> GetGenre([Parameter(DbType="Int")] System.Nullable<int> id)
	{
		IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), id);
		return ((ISingleResult<Genre>)(result.ReturnValue));
	}
	
	[Function(Name="dbo.InsertMovie")]
	public int InsertMovie([Parameter(DbType="NVarChar(100)")] string title, [Parameter(DbType="NVarChar(50)")] string director, [Parameter(DbType="Int")] System.Nullable<int> genre, [Parameter(DbType="Int")] System.Nullable<int> runtime, [Parameter(DbType="DateTime")] System.Nullable<System.DateTime> releasedate)
	{
		IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), title, director, genre, runtime, releasedate);
		return ((int)(result.ReturnValue));
	}
}

[Table(Name="dbo.Movies")]
public partial class Movie : INotifyPropertyChanging, INotifyPropertyChanged
{
	
	private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
	
	private string _Title;
	
	private string _Director;
	
	private int _Genre;
	
	private int _Runtime;
	
	private System.DateTime _ReleaseDate;
	
	private EntityRef<Genre> _Genre1;
	
    #region Extensibility Method Definitions
    partial void OnLoaded();
    partial void OnValidate(System.Data.Linq.ChangeAction action);
    partial void OnCreated();
    partial void OnTitleChanging(string value);
    partial void OnTitleChanged();
    partial void OnDirectorChanging(string value);
    partial void OnDirectorChanged();
    partial void OnGenreChanging(int value);
    partial void OnGenreChanged();
    partial void OnRuntimeChanging(int value);
    partial void OnRuntimeChanged();
    partial void OnReleaseDateChanging(System.DateTime value);
    partial void OnReleaseDateChanged();
    #endregion
	
	public Movie()
	{
		this._Genre1 = default(EntityRef<Genre>);
		OnCreated();
	}
	
	[Column(Storage="_Title", DbType="NChar(100) NOT NULL", CanBeNull=false, IsPrimaryKey=true)]
	public string Title
	{
		get
		{
			return this._Title;
		}
		set
		{
			if ((this._Title != value))
			{
				this.OnTitleChanging(value);
				this.SendPropertyChanging();
				this._Title = value;
				this.SendPropertyChanged("Title");
				this.OnTitleChanged();
			}
		}
	}
	
	[Column(Storage="_Director", DbType="NChar(50) NOT NULL", CanBeNull=false)]
	public string Director
	{
		get
		{
			return this._Director;
		}
		set
		{
			if ((this._Director != value))
			{
				this.OnDirectorChanging(value);
				this.SendPropertyChanging();
				this._Director = value;
				this.SendPropertyChanged("Director");
				this.OnDirectorChanged();
			}
		}
	}
	
	[Column(Storage="_Genre", DbType="Int NOT NULL")]
	public int Genre
	{
		get
		{
			return this._Genre;
		}
		set
		{
			if ((this._Genre != value))
			{
				if (this._Genre1.HasLoadedOrAssignedValue)
				{
					throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
				}
				this.OnGenreChanging(value);
				this.SendPropertyChanging();
				this._Genre = value;
				this.SendPropertyChanged("Genre");
				this.OnGenreChanged();
			}
		}
	}
	
	[Column(Storage="_Runtime", DbType="Int NOT NULL")]
	public int Runtime
	{
		get
		{
			return this._Runtime;
		}
		set
		{
			if ((this._Runtime != value))
			{
				this.OnRuntimeChanging(value);
				this.SendPropertyChanging();
				this._Runtime = value;
				this.SendPropertyChanged("Runtime");
				this.OnRuntimeChanged();
			}
		}
	}
	
	[Column(Storage="_ReleaseDate", DbType="DateTime NOT NULL")]
	public System.DateTime ReleaseDate
	{
		get
		{
			return this._ReleaseDate;
		}
		set
		{
			if ((this._ReleaseDate != value))
			{
				this.OnReleaseDateChanging(value);
				this.SendPropertyChanging();
				this._ReleaseDate = value;
				this.SendPropertyChanged("ReleaseDate");
				this.OnReleaseDateChanged();
			}
		}
	}
	
	[Association(Name="Genre_Movy", Storage="_Genre1", ThisKey="Genre", IsForeignKey=true)]
	public Genre Genre1
	{
		get
		{
			return this._Genre1.Entity;
		}
		set
		{
			Genre previousValue = this._Genre1.Entity;
			if (((previousValue != value) 
						|| (this._Genre1.HasLoadedOrAssignedValue == false)))
			{
				this.SendPropertyChanging();
				if ((previousValue != null))
				{
					this._Genre1.Entity = null;
					previousValue.Movies.Remove(this);
				}
				this._Genre1.Entity = value;
				if ((value != null))
				{
					value.Movies.Add(this);
					this._Genre = value.ID;
				}
				else
				{
					this._Genre = default(int);
				}
				this.SendPropertyChanged("Genre1");
			}
		}
	}
	
	public event PropertyChangingEventHandler PropertyChanging;
	
	public event PropertyChangedEventHandler PropertyChanged;
	
	protected virtual void SendPropertyChanging()
	{
		if ((this.PropertyChanging != null))
		{
			this.PropertyChanging(this, emptyChangingEventArgs);
		}
	}
	
	protected virtual void SendPropertyChanged(String propertyName)
	{
		if ((this.PropertyChanged != null))
		{
			this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
		}
	}
}

[Table(Name="dbo.Genres")]
public partial class Genre : INotifyPropertyChanging, INotifyPropertyChanged
{
	
	private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
	
	private int _ID;
	
	private string _Name;
	
	private EntitySet<Movie> _Movies;
	
    #region Extensibility Method Definitions
    partial void OnLoaded();
    partial void OnValidate(System.Data.Linq.ChangeAction action);
    partial void OnCreated();
    partial void OnIDChanging(int value);
    partial void OnIDChanged();
    partial void OnNameChanging(string value);
    partial void OnNameChanged();
    #endregion
	
	public Genre()
	{
		this._Movies = new EntitySet<Movie>(new Action<Movie>(this.attach_Movies), new Action<Movie>(this.detach_Movies));
		OnCreated();
	}
	
	[Column(Storage="_ID", DbType="Int NOT NULL", IsPrimaryKey=true)]
	public int ID
	{
		get
		{
			return this._ID;
		}
		set
		{
			if ((this._ID != value))
			{
				this.OnIDChanging(value);
				this.SendPropertyChanging();
				this._ID = value;
				this.SendPropertyChanged("ID");
				this.OnIDChanged();
			}
		}
	}
	
	[Column(Storage="_Name", DbType="NChar(20) NOT NULL", CanBeNull=false)]
	public string Name
	{
		get
		{
			return this._Name;
		}
		set
		{
			if ((this._Name != value))
			{
				this.OnNameChanging(value);
				this.SendPropertyChanging();
				this._Name = value;
				this.SendPropertyChanged("Name");
				this.OnNameChanged();
			}
		}
	}
	
	[Association(Name="Genre_Movy", Storage="_Movies", OtherKey="Genre")]
	public EntitySet<Movie> Movies
	{
		get
		{
			return this._Movies;
		}
		set
		{
			this._Movies.Assign(value);
		}
	}
	
	public event PropertyChangingEventHandler PropertyChanging;
	
	public event PropertyChangedEventHandler PropertyChanged;
	
	protected virtual void SendPropertyChanging()
	{
		if ((this.PropertyChanging != null))
		{
			this.PropertyChanging(this, emptyChangingEventArgs);
		}
	}
	
	protected virtual void SendPropertyChanged(String propertyName)
	{
		if ((this.PropertyChanged != null))
		{
			this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
		}
	}
	
	private void attach_Movies(Movie entity)
	{
		this.SendPropertyChanging();
		entity.Genre1 = this;
	}
	
	private void detach_Movies(Movie entity)
	{
		this.SendPropertyChanging();
		entity.Genre1 = null;
	}
}

[Table(Name="dbo.AllMovies")]
public partial class AllMovies
{
	
	private string _Title;
	
	private string _Director;
	
	private System.Nullable<int> _Runtime;
	
	private System.Nullable<System.DateTime> _ReleaseDate;
	
	private string _Genre;
	
	public AllMovies()
	{
	}
	
	[Column(Storage="_Title", DbType="NChar(100)")]
	public string Title
	{
		get
		{
			return this._Title;
		}
		set
		{
			if ((this._Title != value))
			{
				this._Title = value;
			}
		}
	}
	
	[Column(Storage="_Director", DbType="NChar(50)")]
	public string Director
	{
		get
		{
			return this._Director;
		}
		set
		{
			if ((this._Director != value))
			{
				this._Director = value;
			}
		}
	}
	
	[Column(Storage="_Runtime", DbType="Int")]
	public System.Nullable<int> Runtime
	{
		get
		{
			return this._Runtime;
		}
		set
		{
			if ((this._Runtime != value))
			{
				this._Runtime = value;
			}
		}
	}
	
	[Column(Storage="_ReleaseDate", DbType="DateTime")]
	public System.Nullable<System.DateTime> ReleaseDate
	{
		get
		{
			return this._ReleaseDate;
		}
		set
		{
			if ((this._ReleaseDate != value))
			{
				this._ReleaseDate = value;
			}
		}
	}
	
	[Column(Storage="_Genre", DbType="NChar(20)")]
	public string Genre
	{
		get
		{
			return this._Genre;
		}
		set
		{
			if ((this._Genre != value))
			{
				this._Genre = value;
			}
		}
	}
}
#pragma warning restore 1591
