//------------------------------------------------------------------------------
// This is auto-generated code.
//------------------------------------------------------------------------------
// This code was generated by Entity Developer tool using LinqConnect template.
// Code is generated on: 14.10.2015 18:37:41
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//------------------------------------------------------------------------------

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

namespace S11Context
{

    /// <summary>
    /// Виды высокотехнологичной медицинской помощи
    /// </summary>
    [Table(Name = @"s11.rbHighTechCureKind")]
    public partial class RbHighTechCureKind : INotifyPropertyChanging, INotifyPropertyChanged    
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(System.String.Empty);

        private int _Id;

        private System.DateTime _CreateDatetime;

        private System.Nullable<int> _CreatePersonId;

        private System.DateTime _ModifyDatetime;

        private System.Nullable<int> _ModifyPersonId;

        private string _Code;

        private string _Name;

        private string _RegionalCode = @"";

        private string _FederalCode = @"";

        private bool _Deleted;

        private EntitySet<Action> _Actions;

        private EntitySet<Event> _Events;

        private EntityRef<Person> _Person_CreatePersonId;

        private EntityRef<Person> _Person_ModifyPersonId;

        private EntitySet<RbHighTechCureMethod> _RbHighTechCureMethods;
    
        #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 OnCreateDatetimeChanging(System.DateTime value);
        partial void OnCreateDatetimeChanged();
        partial void OnCreatePersonIdChanging(System.Nullable<int> value);
        partial void OnCreatePersonIdChanged();
        partial void OnModifyDatetimeChanging(System.DateTime value);
        partial void OnModifyDatetimeChanged();
        partial void OnModifyPersonIdChanging(System.Nullable<int> value);
        partial void OnModifyPersonIdChanged();
        partial void OnCodeChanging(string value);
        partial void OnCodeChanged();
        partial void OnNameChanging(string value);
        partial void OnNameChanged();
        partial void OnRegionalCodeChanging(string value);
        partial void OnRegionalCodeChanged();
        partial void OnFederalCodeChanging(string value);
        partial void OnFederalCodeChanged();
        partial void OnDeletedChanging(bool value);
        partial void OnDeletedChanged();
        #endregion

        public RbHighTechCureKind()
        {
            this._Actions = new EntitySet<Action>(new Action<Action>(this.attach_Actions), new Action<Action>(this.detach_Actions));
            this._Events = new EntitySet<Event>(new Action<Event>(this.attach_Events), new Action<Event>(this.detach_Events));
            this._Person_CreatePersonId  = default(EntityRef<Person>);
            this._Person_ModifyPersonId  = default(EntityRef<Person>);
            this._RbHighTechCureMethods = new EntitySet<RbHighTechCureMethod>(new Action<RbHighTechCureMethod>(this.attach_RbHighTechCureMethods), new Action<RbHighTechCureMethod>(this.detach_RbHighTechCureMethods));
            OnCreated();
        }

    
        /// <summary>
        /// There are no comments for Id in the schema.
        /// </summary>
        [Column(Name = @"id", Storage = "_Id", AutoSync = AutoSync.OnInsert, CanBeNull = false, DbType = "INT(10) NOT NULL AUTO_INCREMENT", IsDbGenerated = true, 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();
                }
            }
        }

    
        /// <summary>
        /// Дата создания записи
        /// </summary>
        [Column(Name = @"createDatetime", Storage = "_CreateDatetime", CanBeNull = false, DbType = "DATETIME NOT NULL")]
        public System.DateTime CreateDatetime
        {
            get
            {
                return this._CreateDatetime;
            }
            set
            {
                if (this._CreateDatetime != value)
                {
                    this.OnCreateDatetimeChanging(value);
                    this.SendPropertyChanging();
                    this._CreateDatetime = value;
                    this.SendPropertyChanged("CreateDatetime");
                    this.OnCreateDatetimeChanged();
                }
            }
        }

    
        /// <summary>
        /// Автор записи {Person}
        /// </summary>
        [Column(Name = @"createPerson_id", Storage = "_CreatePersonId", DbType = "INT(10)")]
        public System.Nullable<int> CreatePersonId
        {
            get
            {
                return this._CreatePersonId;
            }
            set
            {
                if (this._CreatePersonId != value)
                {
                    if (this._Person_CreatePersonId.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }

                    this.OnCreatePersonIdChanging(value);
                    this.SendPropertyChanging();
                    this._CreatePersonId = value;
                    this.SendPropertyChanged("CreatePersonId");
                    this.OnCreatePersonIdChanged();
                }
            }
        }

    
        /// <summary>
        /// Дата изменения записи
        /// </summary>
        [Column(Name = @"modifyDatetime", Storage = "_ModifyDatetime", CanBeNull = false, DbType = "DATETIME NOT NULL")]
        public System.DateTime ModifyDatetime
        {
            get
            {
                return this._ModifyDatetime;
            }
            set
            {
                if (this._ModifyDatetime != value)
                {
                    this.OnModifyDatetimeChanging(value);
                    this.SendPropertyChanging();
                    this._ModifyDatetime = value;
                    this.SendPropertyChanged("ModifyDatetime");
                    this.OnModifyDatetimeChanged();
                }
            }
        }

    
        /// <summary>
        /// Автор изменения записи {Person}
        /// </summary>
        [Column(Name = @"modifyPerson_id", Storage = "_ModifyPersonId", DbType = "INT(10)")]
        public System.Nullable<int> ModifyPersonId
        {
            get
            {
                return this._ModifyPersonId;
            }
            set
            {
                if (this._ModifyPersonId != value)
                {
                    if (this._Person_ModifyPersonId.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }

                    this.OnModifyPersonIdChanging(value);
                    this.SendPropertyChanging();
                    this._ModifyPersonId = value;
                    this.SendPropertyChanged("ModifyPersonId");
                    this.OnModifyPersonIdChanged();
                }
            }
        }

    
        /// <summary>
        /// Код
        /// </summary>
        [Column(Name = @"code", Storage = "_Code", CanBeNull = false, DbType = "VARCHAR(9) NOT NULL")]
        public string Code
        {
            get
            {
                return this._Code;
            }
            set
            {
                if (this._Code != value)
                {
                    this.OnCodeChanging(value);
                    this.SendPropertyChanging();
                    this._Code = value;
                    this.SendPropertyChanged("Code");
                    this.OnCodeChanged();
                }
            }
        }

    
        /// <summary>
        /// Название
        /// </summary>
        [Column(Name = @"name", Storage = "_Name", CanBeNull = false, DbType = "VARCHAR(400) NOT NULL")]
        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();
                }
            }
        }

    
        /// <summary>
        /// Региональный код
        /// </summary>
        [Column(Name = @"regionalCode", Storage = "_RegionalCode", CanBeNull = false, DbType = "VARCHAR(8) NOT NULL")]
        public string RegionalCode
        {
            get
            {
                return this._RegionalCode;
            }
            set
            {
                if (this._RegionalCode != value)
                {
                    this.OnRegionalCodeChanging(value);
                    this.SendPropertyChanging();
                    this._RegionalCode = value;
                    this.SendPropertyChanged("RegionalCode");
                    this.OnRegionalCodeChanged();
                }
            }
        }

    
        /// <summary>
        /// Федеральный код
        /// </summary>
        [Column(Name = @"federalCode", Storage = "_FederalCode", CanBeNull = false, DbType = "VARCHAR(16) NOT NULL")]
        public string FederalCode
        {
            get
            {
                return this._FederalCode;
            }
            set
            {
                if (this._FederalCode != value)
                {
                    this.OnFederalCodeChanging(value);
                    this.SendPropertyChanging();
                    this._FederalCode = value;
                    this.SendPropertyChanged("FederalCode");
                    this.OnFederalCodeChanged();
                }
            }
        }

    
        /// <summary>
        /// Отметка об удалении
        /// </summary>
        [Column(Name = @"deleted", Storage = "_Deleted", CanBeNull = false, DbType = "TINYINT(1) NOT NULL")]
        public bool Deleted
        {
            get
            {
                return this._Deleted;
            }
            set
            {
                if (this._Deleted != value)
                {
                    this.OnDeletedChanging(value);
                    this.SendPropertyChanging();
                    this._Deleted = value;
                    this.SendPropertyChanged("Deleted");
                    this.OnDeletedChanged();
                }
            }
        }

    
        /// <summary>
        /// There are no comments for Actions in the schema.
        /// </summary>
        [Devart.Data.Linq.Mapping.Association(Name="RbHighTechCureKind_Action", Storage="_Actions", OtherKey="HmpKindId")]
        public EntitySet<Action> Actions
        {
            get
            {
                return this._Actions;
            }
            set
            {
                this._Actions.Assign(value);
            }
        }

    
        /// <summary>
        /// There are no comments for Events in the schema.
        /// </summary>
        [Devart.Data.Linq.Mapping.Association(Name="RbHighTechCureKind_Event", Storage="_Events", OtherKey="HmpKindId")]
        public EntitySet<Event> Events
        {
            get
            {
                return this._Events;
            }
            set
            {
                this._Events.Assign(value);
            }
        }

    
        /// <summary>
        /// There are no comments for Person_CreatePersonId in the schema.
        /// </summary>
        [Devart.Data.Linq.Mapping.Association(Name="Person_Id_RbHighTechCureKind_CreatePersonId", Storage="_Person_CreatePersonId", ThisKey="CreatePersonId", IsForeignKey=true)]
        public Person Person_CreatePersonId
        {
            get
            {
                return this._Person_CreatePersonId.Entity;
            }
            set
            {
                Person previousValue = this._Person_CreatePersonId.Entity;
                if ((previousValue != value) || (this._Person_CreatePersonId.HasLoadedOrAssignedValue == false))
                {
                    this.SendPropertyChanging();
                    if (previousValue != null)
                    {
                        this._Person_CreatePersonId.Entity = null;
                        previousValue.RbHighTechCureKinds_CreatePersonId.Remove(this);
                    }
                    this._Person_CreatePersonId.Entity = value;
                    if (value != null)
                    {
                        this._CreatePersonId = value.Id;
                        value.RbHighTechCureKinds_CreatePersonId.Add(this);
                    }
                    else
                    {
                        this._CreatePersonId = default(System.Nullable<int>);
                    }
                    this.SendPropertyChanged("Person_CreatePersonId");
                }
            }
        }

    
        /// <summary>
        /// There are no comments for Person_ModifyPersonId in the schema.
        /// </summary>
        [Devart.Data.Linq.Mapping.Association(Name="Person_Id_RbHighTechCureKind_ModifyPersonId", Storage="_Person_ModifyPersonId", ThisKey="ModifyPersonId", IsForeignKey=true)]
        public Person Person_ModifyPersonId
        {
            get
            {
                return this._Person_ModifyPersonId.Entity;
            }
            set
            {
                Person previousValue = this._Person_ModifyPersonId.Entity;
                if ((previousValue != value) || (this._Person_ModifyPersonId.HasLoadedOrAssignedValue == false))
                {
                    this.SendPropertyChanging();
                    if (previousValue != null)
                    {
                        this._Person_ModifyPersonId.Entity = null;
                        previousValue.RbHighTechCureKinds_ModifyPersonId.Remove(this);
                    }
                    this._Person_ModifyPersonId.Entity = value;
                    if (value != null)
                    {
                        this._ModifyPersonId = value.Id;
                        value.RbHighTechCureKinds_ModifyPersonId.Add(this);
                    }
                    else
                    {
                        this._ModifyPersonId = default(System.Nullable<int>);
                    }
                    this.SendPropertyChanged("Person_ModifyPersonId");
                }
            }
        }

    
        /// <summary>
        /// There are no comments for RbHighTechCureMethods in the schema.
        /// </summary>
        [Devart.Data.Linq.Mapping.Association(Name="RbHighTechCureKind_RbHighTechCureMethod", Storage="_RbHighTechCureMethods", OtherKey="CureKindId", DeleteRule="CASCADE")]
        public EntitySet<RbHighTechCureMethod> RbHighTechCureMethods
        {
            get
            {
                return this._RbHighTechCureMethods;
            }
            set
            {
                this._RbHighTechCureMethods.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 SendPropertyChanging(System.String propertyName) 
        {
            if (this.PropertyChanging != null)
                this.PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
        }

        protected virtual void SendPropertyChanged(System.String propertyName)
        {
             if (this.PropertyChanged != null)
                 this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        private void attach_Actions(Action entity)
        {
            this.SendPropertyChanging("Actions");
            entity.RbHighTechCureKind = this;
        }
    
        private void detach_Actions(Action entity)
        {
            this.SendPropertyChanging("Actions");
            entity.RbHighTechCureKind = null;
        }

        private void attach_Events(Event entity)
        {
            this.SendPropertyChanging("Events");
            entity.RbHighTechCureKind = this;
        }
    
        private void detach_Events(Event entity)
        {
            this.SendPropertyChanging("Events");
            entity.RbHighTechCureKind = null;
        }

        private void attach_RbHighTechCureMethods(RbHighTechCureMethod entity)
        {
            this.SendPropertyChanging("RbHighTechCureMethods");
            entity.RbHighTechCureKind = this;
        }
    
        private void detach_RbHighTechCureMethods(RbHighTechCureMethod entity)
        {
            this.SendPropertyChanging("RbHighTechCureMethods");
            entity.RbHighTechCureKind = null;
        }
    }

}
