PageRenderTime 37ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/DAL/Repositories/EntityFramework4/Category.cs

#
C# | 339 lines | 284 code | 45 blank | 10 comment | 57 complexity | 34dc705164f61bf5ff6ac1ff2e26816c MD5 | raw file
  1. //------------------------------------------------------------------------------
  2. // <auto-generated>
  3. // This code was generated from a template.
  4. //
  5. // Changes to this file may cause incorrect behavior and will be lost if
  6. // the code is regenerated.
  7. // </auto-generated>
  8. //------------------------------------------------------------------------------
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Collections.ObjectModel;
  12. using System.Collections.Specialized;
  13. using System.ComponentModel;
  14. using System.Globalization;
  15. using System.Runtime.Serialization;
  16. using System.Linq;
  17. using System.Diagnostics;
  18. using MoneyManagerNET.Infrastructure;
  19. namespace MoneyManagerNET.DAL.Repository.EF4
  20. {
  21. [DataContract(IsReference = true)]
  22. [KnownType(typeof(SubCategory))]
  23. [KnownType(typeof(Transaction))]
  24. public partial class Category: MoneyManagerNET.Model.ICategory, IObjectWithChangeTracker, INotifyPropertyChanged
  25. {
  26. static TraceSource trace = new TraceSource("storage");
  27. #region Primitive Properties
  28. [DataMember]
  29. public int Id
  30. {
  31. get { return _id; }
  32. set
  33. {
  34. if (_id != value)
  35. {
  36. if (ChangeTracker.ChangeTrackingEnabled && ChangeTracker.State != ObjectState.Added)
  37. {
  38. 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.");
  39. }
  40. _id = value;
  41. OnPropertyChanged("Id");
  42. }
  43. }
  44. }
  45. private int _id;
  46. [DataMember]
  47. public string Name
  48. {
  49. get { return _name; }
  50. set
  51. {
  52. if (_name != value)
  53. {
  54. _name = value;
  55. OnPropertyChanged("Name");
  56. }
  57. }
  58. }
  59. private string _name;
  60. #endregion
  61. #region Navigation Properties
  62. CovariantWrapper<Model.ISubCategory,SubCategory> baseSubCategoryList=null;
  63. ICollection<Model.ISubCategory> Model.ICategory.SubCategoryList{
  64. get{
  65. return baseSubCategoryList??(baseSubCategoryList=new CovariantWrapper<Model.ISubCategory,SubCategory>(this.SubCategoryList));
  66. //this.SubCategoryList.Cast<Model.ISubCategory>() ;
  67. }
  68. set{}
  69. }
  70. [DataMember]
  71. public TrackableCollection<SubCategory> SubCategoryList
  72. {
  73. get
  74. {
  75. if (_subCategoryList == null)
  76. {
  77. _subCategoryList = new TrackableCollection<SubCategory>();
  78. _subCategoryList.CollectionChanged += FixupSubCategoryList;
  79. }
  80. return _subCategoryList;
  81. }
  82. set
  83. {
  84. if (!ReferenceEquals(_subCategoryList, value))
  85. {
  86. if (ChangeTracker.ChangeTrackingEnabled)
  87. {
  88. throw new InvalidOperationException("Cannot set the FixupChangeTrackingCollection when ChangeTracking is enabled");
  89. }
  90. if (_subCategoryList != null)
  91. {
  92. _subCategoryList.CollectionChanged -= FixupSubCategoryList;
  93. }
  94. _subCategoryList = value;
  95. if (_subCategoryList != null)
  96. {
  97. _subCategoryList.CollectionChanged += FixupSubCategoryList;
  98. }
  99. OnNavigationPropertyChanged("SubCategoryList");
  100. }
  101. }
  102. }
  103. private TrackableCollection<SubCategory> _subCategoryList;
  104. CovariantWrapper<Model.ITransaction,Transaction> baseTransaction=null;
  105. ICollection<Model.ITransaction> Model.ICategory.Transaction{
  106. get{
  107. return baseTransaction??(baseTransaction=new CovariantWrapper<Model.ITransaction,Transaction>(this.Transaction));
  108. //this.Transaction.Cast<Model.ITransaction>() ;
  109. }
  110. set{}
  111. }
  112. [DataMember]
  113. public TrackableCollection<Transaction> Transaction
  114. {
  115. get
  116. {
  117. if (_transaction == null)
  118. {
  119. _transaction = new TrackableCollection<Transaction>();
  120. _transaction.CollectionChanged += FixupTransaction;
  121. }
  122. return _transaction;
  123. }
  124. set
  125. {
  126. if (!ReferenceEquals(_transaction, value))
  127. {
  128. if (ChangeTracker.ChangeTrackingEnabled)
  129. {
  130. throw new InvalidOperationException("Cannot set the FixupChangeTrackingCollection when ChangeTracking is enabled");
  131. }
  132. if (_transaction != null)
  133. {
  134. _transaction.CollectionChanged -= FixupTransaction;
  135. }
  136. _transaction = value;
  137. if (_transaction != null)
  138. {
  139. _transaction.CollectionChanged += FixupTransaction;
  140. }
  141. OnNavigationPropertyChanged("Transaction");
  142. }
  143. }
  144. }
  145. private TrackableCollection<Transaction> _transaction;
  146. #endregion
  147. #region ChangeTracking
  148. protected virtual void OnPropertyChanged(String propertyName)
  149. {
  150. if (ChangeTracker.State != ObjectState.Added && ChangeTracker.State != ObjectState.Deleted)
  151. {
  152. ChangeTracker.State = ObjectState.Modified;
  153. }
  154. if (_propertyChanged != null)
  155. {
  156. _propertyChanged(this, new PropertyChangedEventArgs(propertyName));
  157. }
  158. }
  159. protected virtual void OnNavigationPropertyChanged(String propertyName)
  160. {
  161. if (_propertyChanged != null)
  162. {
  163. _propertyChanged(this, new PropertyChangedEventArgs(propertyName));
  164. }
  165. }
  166. event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged{ add { _propertyChanged += value; } remove { _propertyChanged -= value; } }
  167. private event PropertyChangedEventHandler _propertyChanged;
  168. private ObjectChangeTracker _changeTracker;
  169. [DataMember]
  170. public ObjectChangeTracker ChangeTracker
  171. {
  172. get
  173. {
  174. if (_changeTracker == null)
  175. {
  176. _changeTracker = new ObjectChangeTracker();
  177. _changeTracker.ObjectStateChanging += HandleObjectStateChanging;
  178. }
  179. return _changeTracker;
  180. }
  181. set
  182. {
  183. if(_changeTracker != null)
  184. {
  185. _changeTracker.ObjectStateChanging -= HandleObjectStateChanging;
  186. }
  187. _changeTracker = value;
  188. if(_changeTracker != null)
  189. {
  190. _changeTracker.ObjectStateChanging += HandleObjectStateChanging;
  191. }
  192. }
  193. }
  194. private void HandleObjectStateChanging(object sender, ObjectStateChangingEventArgs e)
  195. {
  196. if (e.NewState == ObjectState.Deleted)
  197. {
  198. ClearNavigationProperties();
  199. }
  200. }
  201. protected bool IsDeserializing { get; private set; }
  202. [OnDeserializing]
  203. public void OnDeserializingMethod(StreamingContext context)
  204. {
  205. IsDeserializing = true;
  206. }
  207. [OnDeserialized]
  208. public void OnDeserializedMethod(StreamingContext context)
  209. {
  210. IsDeserializing = false;
  211. ChangeTracker.ChangeTrackingEnabled = true;
  212. }
  213. protected virtual void ClearNavigationProperties()
  214. {
  215. SubCategoryList.Clear();
  216. Transaction.Clear();
  217. }
  218. #endregion
  219. #region Association Fixup
  220. private void FixupSubCategoryList(object sender, NotifyCollectionChangedEventArgs e)
  221. {
  222. if (IsDeserializing)
  223. {
  224. return;
  225. }
  226. if (e.NewItems != null)
  227. {
  228. foreach (SubCategory item in e.NewItems)
  229. {
  230. item.Category = this;
  231. if (ChangeTracker.ChangeTrackingEnabled)
  232. {
  233. if (!item.ChangeTracker.ChangeTrackingEnabled)
  234. {
  235. item.StartTracking();
  236. }
  237. ChangeTracker.RecordAdditionToCollectionProperties("SubCategoryList", item);
  238. }
  239. }
  240. }
  241. if (e.OldItems != null)
  242. {
  243. foreach (SubCategory item in e.OldItems)
  244. {
  245. if (ReferenceEquals(item.Category, this))
  246. {
  247. item.Category = null;
  248. }
  249. if (ChangeTracker.ChangeTrackingEnabled)
  250. {
  251. ChangeTracker.RecordRemovalFromCollectionProperties("SubCategoryList", item);
  252. }
  253. }
  254. }
  255. }
  256. private void FixupTransaction(object sender, NotifyCollectionChangedEventArgs e)
  257. {
  258. if (IsDeserializing)
  259. {
  260. return;
  261. }
  262. if (e.NewItems != null)
  263. {
  264. foreach (Transaction item in e.NewItems)
  265. {
  266. item.Category = this;
  267. if (ChangeTracker.ChangeTrackingEnabled)
  268. {
  269. if (!item.ChangeTracker.ChangeTrackingEnabled)
  270. {
  271. item.StartTracking();
  272. }
  273. ChangeTracker.RecordAdditionToCollectionProperties("Transaction", item);
  274. }
  275. }
  276. }
  277. if (e.OldItems != null)
  278. {
  279. foreach (Transaction item in e.OldItems)
  280. {
  281. if (ReferenceEquals(item.Category, this))
  282. {
  283. item.Category = null;
  284. }
  285. if (ChangeTracker.ChangeTrackingEnabled)
  286. {
  287. ChangeTracker.RecordRemovalFromCollectionProperties("Transaction", item);
  288. }
  289. }
  290. }
  291. }
  292. #endregion
  293. }
  294. }