//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated from a template.
//
//     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.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.Serialization;

namespace WWWings_GO
{
    [DataContract(IsReference = true)]
    [KnownType(typeof(Flug))]
    public partial class Pilot : Person, IObjectWithChangeTracker, INotifyPropertyChanged
    {
        #region Primitive Properties
    
        [DataMember]
        public System.DateTime Eingestellungsdatum
        {
            get { return _eingestellungsdatum; }
            set
            {
                if (_eingestellungsdatum != value)
                {
                    _eingestellungsdatum = value;
                    OnPropertyChanged("Eingestellungsdatum");
                }
            }
        }
        private System.DateTime _eingestellungsdatum;

        #endregion
        #region Navigation Properties
    
        [DataMember]
        public TrackableCollection<Flug> Flug
        {
            get
            {
                if (_flug == null)
                {
                    _flug = new TrackableCollection<Flug>();
                    _flug.CollectionChanged += FixupFlug;
                }
                return _flug;
            }
            set
            {
                if (!ReferenceEquals(_flug, value))
                {
                    if (ChangeTracker.ChangeTrackingEnabled)
                    {
                        throw new InvalidOperationException("Cannot set the FixupChangeTrackingCollection when ChangeTracking is enabled");
                    }
                    if (_flug != null)
                    {
                        _flug.CollectionChanged -= FixupFlug;
                    }
                    _flug = value;
                    if (_flug != null)
                    {
                        _flug.CollectionChanged += FixupFlug;
                    }
                    OnNavigationPropertyChanged("Flug");
                }
            }
        }
        private TrackableCollection<Flug> _flug;

        #endregion
        #region ChangeTracking
    
        protected override void ClearNavigationProperties()
        {
            base.ClearNavigationProperties();
            Flug.Clear();
        }

        #endregion
        #region Association Fixup
    
        private void FixupFlug(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (IsDeserializing)
            {
                return;
            }
    
            if (e.NewItems != null)
            {
                foreach (Flug item in e.NewItems)
                {
                    item.Pilot = this;
                    if (ChangeTracker.ChangeTrackingEnabled)
                    {
                        if (!item.ChangeTracker.ChangeTrackingEnabled)
                        {
                            item.StartTracking();
                        }
                        ChangeTracker.RecordAdditionToCollectionProperties("Flug", item);
                    }
                }
            }
    
            if (e.OldItems != null)
            {
                foreach (Flug item in e.OldItems)
                {
                    if (ReferenceEquals(item.Pilot, this))
                    {
                        item.Pilot = null;
                    }
                    if (ChangeTracker.ChangeTrackingEnabled)
                    {
                        ChangeTracker.RecordRemovalFromCollectionProperties("Flug", item);
                    }
                }
            }
        }

        #endregion
    }
}
