/DAL/Repositories/EntityFramework4/Category.cs
C# | 339 lines | 284 code | 45 blank | 10 comment | 57 complexity | 34dc705164f61bf5ff6ac1ff2e26816c MD5 | raw file
- //------------------------------------------------------------------------------
- // <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;
- using System.Linq;
- using System.Diagnostics;
-
-
- using MoneyManagerNET.Infrastructure;
-
-
- namespace MoneyManagerNET.DAL.Repository.EF4
- {
- [DataContract(IsReference = true)]
- [KnownType(typeof(SubCategory))]
- [KnownType(typeof(Transaction))]
- public partial class Category: MoneyManagerNET.Model.ICategory, IObjectWithChangeTracker, INotifyPropertyChanged
- {
-
- static TraceSource trace = new TraceSource("storage");
-
-
- #region Primitive Properties
-
-
- [DataMember]
- public int Id
- {
- get { return _id; }
- set
- {
- if (_id != value)
- {
- if (ChangeTracker.ChangeTrackingEnabled && ChangeTracker.State != ObjectState.Added)
- {
- throw new InvalidOperationException("The property 'Id' is part of the object's key and cannot be changed. Changes to key properties can only be made when the object is not being tracked or is in the Added state.");
- }
- _id = value;
- OnPropertyChanged("Id");
- }
- }
- }
- private int _id;
-
-
- [DataMember]
- public string Name
- {
- get { return _name; }
- set
- {
- if (_name != value)
- {
- _name = value;
- OnPropertyChanged("Name");
- }
- }
- }
- private string _name;
-
- #endregion
- #region Navigation Properties
-
-
-
- CovariantWrapper<Model.ISubCategory,SubCategory> baseSubCategoryList=null;
-
- ICollection<Model.ISubCategory> Model.ICategory.SubCategoryList{
- get{
- return baseSubCategoryList??(baseSubCategoryList=new CovariantWrapper<Model.ISubCategory,SubCategory>(this.SubCategoryList));
- //this.SubCategoryList.Cast<Model.ISubCategory>() ;
- }
- set{}
- }
-
-
- [DataMember]
- public TrackableCollection<SubCategory> SubCategoryList
- {
- get
- {
- if (_subCategoryList == null)
- {
- _subCategoryList = new TrackableCollection<SubCategory>();
- _subCategoryList.CollectionChanged += FixupSubCategoryList;
- }
- return _subCategoryList;
- }
- set
- {
- if (!ReferenceEquals(_subCategoryList, value))
- {
- if (ChangeTracker.ChangeTrackingEnabled)
- {
- throw new InvalidOperationException("Cannot set the FixupChangeTrackingCollection when ChangeTracking is enabled");
- }
- if (_subCategoryList != null)
- {
- _subCategoryList.CollectionChanged -= FixupSubCategoryList;
- }
- _subCategoryList = value;
- if (_subCategoryList != null)
- {
- _subCategoryList.CollectionChanged += FixupSubCategoryList;
- }
- OnNavigationPropertyChanged("SubCategoryList");
- }
- }
- }
- private TrackableCollection<SubCategory> _subCategoryList;
-
-
-
- CovariantWrapper<Model.ITransaction,Transaction> baseTransaction=null;
-
- ICollection<Model.ITransaction> Model.ICategory.Transaction{
- get{
- return baseTransaction??(baseTransaction=new CovariantWrapper<Model.ITransaction,Transaction>(this.Transaction));
- //this.Transaction.Cast<Model.ITransaction>() ;
- }
- set{}
- }
-
-
- [DataMember]
- public TrackableCollection<Transaction> Transaction
- {
- get
- {
- if (_transaction == null)
- {
- _transaction = new TrackableCollection<Transaction>();
- _transaction.CollectionChanged += FixupTransaction;
- }
- return _transaction;
- }
- set
- {
- if (!ReferenceEquals(_transaction, value))
- {
- if (ChangeTracker.ChangeTrackingEnabled)
- {
- throw new InvalidOperationException("Cannot set the FixupChangeTrackingCollection when ChangeTracking is enabled");
- }
- if (_transaction != null)
- {
- _transaction.CollectionChanged -= FixupTransaction;
- }
- _transaction = value;
- if (_transaction != null)
- {
- _transaction.CollectionChanged += FixupTransaction;
- }
- OnNavigationPropertyChanged("Transaction");
- }
- }
- }
- private TrackableCollection<Transaction> _transaction;
-
- #endregion
- #region ChangeTracking
-
- protected virtual void OnPropertyChanged(String propertyName)
- {
- if (ChangeTracker.State != ObjectState.Added && ChangeTracker.State != ObjectState.Deleted)
- {
- ChangeTracker.State = ObjectState.Modified;
- }
- if (_propertyChanged != null)
- {
- _propertyChanged(this, new PropertyChangedEventArgs(propertyName));
- }
- }
-
- protected virtual void OnNavigationPropertyChanged(String propertyName)
- {
- if (_propertyChanged != null)
- {
- _propertyChanged(this, new PropertyChangedEventArgs(propertyName));
- }
- }
-
- event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged{ add { _propertyChanged += value; } remove { _propertyChanged -= value; } }
- private event PropertyChangedEventHandler _propertyChanged;
- private ObjectChangeTracker _changeTracker;
-
- [DataMember]
- public ObjectChangeTracker ChangeTracker
- {
- get
- {
- if (_changeTracker == null)
- {
- _changeTracker = new ObjectChangeTracker();
- _changeTracker.ObjectStateChanging += HandleObjectStateChanging;
- }
- return _changeTracker;
- }
- set
- {
- if(_changeTracker != null)
- {
- _changeTracker.ObjectStateChanging -= HandleObjectStateChanging;
- }
- _changeTracker = value;
- if(_changeTracker != null)
- {
- _changeTracker.ObjectStateChanging += HandleObjectStateChanging;
- }
- }
- }
-
- private void HandleObjectStateChanging(object sender, ObjectStateChangingEventArgs e)
- {
- if (e.NewState == ObjectState.Deleted)
- {
- ClearNavigationProperties();
- }
- }
-
- protected bool IsDeserializing { get; private set; }
-
- [OnDeserializing]
- public void OnDeserializingMethod(StreamingContext context)
- {
- IsDeserializing = true;
- }
-
- [OnDeserialized]
- public void OnDeserializedMethod(StreamingContext context)
- {
- IsDeserializing = false;
- ChangeTracker.ChangeTrackingEnabled = true;
- }
-
- protected virtual void ClearNavigationProperties()
- {
- SubCategoryList.Clear();
- Transaction.Clear();
- }
-
- #endregion
- #region Association Fixup
-
- private void FixupSubCategoryList(object sender, NotifyCollectionChangedEventArgs e)
- {
- if (IsDeserializing)
- {
- return;
- }
-
- if (e.NewItems != null)
- {
- foreach (SubCategory item in e.NewItems)
- {
- item.Category = this;
-
- if (ChangeTracker.ChangeTrackingEnabled)
- {
- if (!item.ChangeTracker.ChangeTrackingEnabled)
- {
- item.StartTracking();
- }
- ChangeTracker.RecordAdditionToCollectionProperties("SubCategoryList", item);
- }
- }
- }
-
- if (e.OldItems != null)
- {
- foreach (SubCategory item in e.OldItems)
- {
- if (ReferenceEquals(item.Category, this))
- {
- item.Category = null;
- }
- if (ChangeTracker.ChangeTrackingEnabled)
- {
- ChangeTracker.RecordRemovalFromCollectionProperties("SubCategoryList", item);
- }
- }
- }
- }
-
- private void FixupTransaction(object sender, NotifyCollectionChangedEventArgs e)
- {
- if (IsDeserializing)
- {
- return;
- }
-
- if (e.NewItems != null)
- {
- foreach (Transaction item in e.NewItems)
- {
- item.Category = this;
-
- if (ChangeTracker.ChangeTrackingEnabled)
- {
- if (!item.ChangeTracker.ChangeTrackingEnabled)
- {
- item.StartTracking();
- }
- ChangeTracker.RecordAdditionToCollectionProperties("Transaction", item);
- }
- }
- }
-
- if (e.OldItems != null)
- {
- foreach (Transaction item in e.OldItems)
- {
- if (ReferenceEquals(item.Category, this))
- {
- item.Category = null;
- }
- if (ChangeTracker.ChangeTrackingEnabled)
- {
- ChangeTracker.RecordRemovalFromCollectionProperties("Transaction", item);
- }
- }
- }
- }
-
- #endregion
- }
- }