context: using System; 
  using System.Data.Linq;
  using System.Data.Linq.Mapping;
  using System.Data;
  using System.Collections.Generic;
  using System.Reflection;
  using System.Linq;
  using System.Linq.Expressions;
  using System.ComponentModel;
  using CmsData.Infrastructure;
  
  namespace CmsData
  {
  	[Table(Name="dbo.TagPerson")]
  	public partial class TagPerson : INotifyPropertyChanging, INotifyPropertyChanged
  	{
  		private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
  		
  	#region Private Fields
  		
  		private int _Id;
  		
  		private int _PeopleId;
  		
  		private DateTime? _DateCreated;
  		
     		
      	
  		private EntityRef< Tag> _Tag;
  		
  		private EntityRef< Person> _Person;
  		
  	#endregion
  	
      #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 OnPeopleIdChanging(int value);
  		partial void OnPeopleIdChanged();
  		
  		partial void OnDateCreatedChanging(DateTime? value);
  		partial void OnDateCreatedChanged();
  		
      #endregion
  		public TagPerson()
  		{
  			
  			
  			this._Tag = default(EntityRef< Tag>); 
  			
  			this._Person = default(EntityRef< Person>); 
  			
  			OnCreated();
  		}
  
  		
      #region Columns
  		
  		[Column(Name="Id", UpdateCheck=UpdateCheck.Never, Storage="_Id", DbType="int NOT NULL", IsPrimaryKey=true)]
  		[IsForeignKey]
  		public int Id
  		{
  			get { return this._Id; }
  
  			set
  			{
  				if (this._Id != value)
  				{
  				
  					if (this._Tag.HasLoadedOrAssignedValue)
  						throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
  				
                      this.OnIdChanging(value);
  					this.SendPropertyChanging();
  					this._Id = value;
  					this.SendPropertyChanged("Id");
  					this.OnIdChanged();
  				}
  
  			}
  
  		}
  
  		
  		[Column(Name="PeopleId", UpdateCheck=UpdateCheck.Never, Storage="_PeopleId", DbType="int NOT NULL", IsPrimaryKey=true)]
  		[IsForeignKey]
  		public int PeopleId
  		{
  			get { return this._PeopleId; }
  
  			set
  			{
  				if (this._PeopleId != value)
  				{
  				
  					if (this._Person.HasLoadedOrAssignedValue)
  						throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
  				
                      this.OnPeopleIdChanging(value);
  					this.SendPropertyChanging();
  					this._PeopleId = value;
  					this.SendPropertyChanged("PeopleId");
  					this.OnPeopleIdChanged();
  				}
  
  			}
  
  		}
  
  		
  		[Column(Name="DateCreated", UpdateCheck=UpdateCheck.Never, Storage="_DateCreated", DbType="datetime")]
  		public DateTime? DateCreated
  		{
  			get { return this._DateCreated; }
  
  			set
  			{
  				if (this._DateCreated != value)
  				{
  				
                      this.OnDateCreatedChanging(value);
  					this.SendPropertyChanging();
  					this._DateCreated = value;
  					this.SendPropertyChanged("DateCreated");
  					this.OnDateCreatedChanged();
  				}
  
  			}
  
  		}
  
  		
      #endregion
          
      #region Foreign Key Tables
     		
  	#endregion
  	
  	#region Foreign Keys
      	
  		[Association(Name="PersonTags__Tag", Storage="_Tag", ThisKey="Id", IsForeignKey=true)]
  		public Tag Tag
  		{
  			get { return this._Tag.Entity; }
  
  			set
  			{
  				Tag previousValue = this._Tag.Entity;
  				if (((previousValue != value) 
  							|| (this._Tag.HasLoadedOrAssignedValue == false)))
  				{
  					this.SendPropertyChanging();
  					if (previousValue != null)
  					{
  						this._Tag.Entity = null;
  						previousValue.PersonTags.Remove(this);
  					}
  
  					this._Tag.Entity = value;
  					if (value != null)
  					{
  						value.PersonTags.Add(this);
  						
  						this._Id = value.Id;
  						
  					}
  
  					else
  					{
  						
  						this._Id = default(int);
  						
  					}
  
  					this.SendPropertyChanged("Tag");
  				}
  
  			}
  
  		}
  
  		
  		[Association(Name="Tags__Person", Storage="_Person", ThisKey="PeopleId", IsForeignKey=true)]
  		public Person Person
  		{
  			get { return this._Person.Entity; }
  
  			set
  			{
  				Person previousValue = this._Person.Entity;
  				if (((previousValue != value) 
  							|| (this._Person.HasLoadedOrAssignedValue == false)))
  				{
  					this.SendPropertyChanging();
  					if (previousValue != null)
  					{
  						this._Person.Entity = null;
  						previousValue.Tags.Remove(this);
  					}
  
  					this._Person.Entity = value;
  					if (value != null)
  					{
  						value.Tags.Add(this);
  						
  						this._PeopleId = value.PeopleId;
  						
  					}
  
  					else
  					{
  						
  
gt: 						this._PeopleId = default(int);