//------------------------------------------------------------------------------
// <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;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Resources;
using System.Runtime.Serialization;
using System.Text;
using System.Xml.Linq;
#if WPF
namespace SchoolSample.EntityModel
{
public partial class Student : Person, IClientChangeTracking, IChangeTracking, IRevertibleChangeTracking,
INotifyDataErrorInfo, INodeLevel, IEditableObject
{
#region IClientChangeTracking Interface
/// <summary>
/// Accepts changes made to the entity object
/// </summary>
void IClientChangeTracking.AcceptChanges()
{
this.AcceptChanges();
}
/// <summary>
/// Rejects changes made to the entity object
/// </summary>
void IClientChangeTracking.RejectChanges()
{
this.RejectChanges();
}
/// <summary>
/// Accepts changes made to the entity object and all objects of its object graph
/// </summary>
public override void AcceptObjectGraphChanges()
{
this.AcceptChanges();
// call AccetChanges() on all Navigation properties
foreach (var item in Enrollments)
item.AcceptChanges();
// call base AcceptObjectGraphChanges()
base.AcceptObjectGraphChanges();
}
/// <summary>
/// Rejects changes made to the entity object and all objects of its object graph
/// </summary>
public override void RejectObjectGraphChanges()
{
this.RejectChanges();
// call RejectChanges() on all Navigation properties
foreach (var item in Enrollments)
item.RejectChanges();
// call base RejectObjectGraphChanges()
base.RejectObjectGraphChanges();
}
internal override bool ObjectGraphHasChanges(ref List<object> visitedGraph)
{
// if already visited this object, just return false
if (visitedGraph.Any(n => ReferenceEquals(n, this))) return false;
var hasChanges = base.ObjectGraphHasChanges(ref visitedGraph);
if (hasChanges) return true;
// if not, add itself to the visited graph
if (visitedGraph.All(i => !ReferenceEquals(i, this))) visitedGraph.Add(this);
// call ObjectGraphHasChanges() on all Navigation properties
foreach (var item in Enrollments)
{
hasChanges = item.ObjectGraphHasChanges(ref visitedGraph);
if (hasChanges) return true;
}
return false;
}
internal override bool ObjectGraphHasChanges(Dictionary<INodeLevel, int> nodeLevelDictionary)
{
var hasChanges = base.ObjectGraphHasChanges(nodeLevelDictionary);
if (hasChanges) return true;
// if not, find out the current node level
var currentLevel = nodeLevelDictionary.Single(n => ReferenceEquals(n.Key, this)).Value;
// call ObjectGraphHasChanges() on all Navigation properties of the next level
foreach (var item in Enrollments)
{
if (nodeLevelDictionary.Any(n => ReferenceEquals(n.Key, item) && n.Value == (currentLevel + 1)))
{
hasChanges = item.ObjectGraphHasChanges(nodeLevelDictionary);
if (hasChanges) return true;
}
}
return false;
}
public override List<INodeLevel> GetNextLevelNodes(Dictionary<INodeLevel, int> nodeLevelDictionary)
{
// call base GetNextLevelNodes()
var nextLevelNodes = base.GetNextLevelNodes(nodeLevelDictionary);
// loop through Navigation properties to add next level nodes
nextLevelNodes.AddRange(
Enrollments.Where(
n => nodeLevelDictionary
.All(i => !ReferenceEquals(i.Key, n))));
return nextLevelNodes;
}
internal override void EstimateObjectGraphSize(ref long size, ref List<object> visitedGraph)
{
// if already visited this object, just return
if (visitedGraph.Any(n => ReferenceEquals(n, this))) return;
// call base EstimateObjectGraphSize()
base.EstimateObjectGraphSize(ref size, ref visitedGraph);
size += EstimateSize;
// add itself to the visited graph
if (visitedGraph.All(i => !ReferenceEquals(i, this))) visitedGraph.Add(this);
// call EstimateObjectGraphSize() on all Navigation properties
foreach (var item in Enrollments)
{
item.EstimateObjectGraphSize(ref size, ref visitedGraph);
}
}
internal override void EstimateObjectGraphChangeSize(ref long size, Dictionary<INodeLevel, int> nodeLevelDictionary)
{
// call base EstimateObjectGraphChangeSize()
base.EstimateObjectGraphChangeSize(ref size, nodeLevelDictionary);
size += EstimateSize;
// find out the current node level
var currentLevel = nodeLevelDictionary.Single(n => ReferenceEquals(n.Key, this)).Value;
// call EstimateObjectGraphChangeSize() on all Navigation properties that has change
foreach (var item in Enrollments)
{
if (nodeLevelDictionary.Any(n => ReferenceEquals(n.Key, item) && n.Value != (currentLevel - 1)))
{
if (ChangeTracker.ObjectsAddedToCollectionProperties.ContainsKey("Enrollments")
&& ChangeTracker.ObjectsAddedToCollectionProperties["Enrollments"].Contains(item))
{
// if item exists in ObjectsAddedToCollectionProperties, we need to add its size
item.EstimateObjectGraphChangeSize(ref size, nodeLevelDictionary);
}
else if (item.ObjectGraphHasChanges(nodeLevelDictionary))
{
// if item has changes, we also need to add its size
item.EstimateObjectGraphChangeSize(ref size, nodeLevelDictionary);
}
}
}
}
internal override void TrimUnchangedEntities(Dictionary<INodeLevel, int> nodeLevelDictionary)
{
// call base TrimUnchangedEntities() first
base.TrimUnchangedEntities(nodeLevelDictionary);
bool changeTrackingEnabled = ChangeTracker.ChangeTrackingEnabled;
this.StopTracking();
// find out the current node level
var currentLevel = nodeLevelDictionary.Single(n => ReferenceEquals(n.Key, this)).Value;
// trim all navigation property items that do not have any change
foreach (var item in Enrollments.ToList())
{
if (nodeLevelDictionary.Any(n => ReferenceEquals(n.Key, item) && n.Value != (currentLevel - 1)))
{
if (ChangeTracker.ObjectsAddedToCollectionProperties.ContainsKey("Enrollments")
&& ChangeTracker.ObjectsAddedToCollectionProperties["Enrollments"].Contains(item))
{
// if item exists in ObjectsAddedToCollectionProperties, we need to keep it
item.TrimUnchangedEntities(nodeLevelDictionary);
}
else if (item.ObjectGraphHasChanges(nodeLevelDictionary))
{
// if n has changes, we also need to keep it
item.TrimUnchangedEntities(nodeLevelDictionary);
}
else
{
Enrollments.Remove(item);
}
}
}
ChangeTracker.ChangeTrackingEnabled = changeTrackingEnabled;
}
#endregion
#region IClientChangeTracking Helper Property
internal override long EstimateSize
{
get
{
long _size = 0;
// estimate size of all Simple Properties
_size += sizeof(ulong); // EnrollmentDate
return _size;
}
}
#endregion
#region IChangeTracking and IRevertibleChangeTracking interfaces
void IChangeTracking.AcceptChanges()
{
this.AcceptChanges();
}
bool IChangeTracking.IsChanged
{
get { return HasChanges; }
}
void IRevertibleChangeTracking.RejectChanges()
{
this.RejectChanges();
}
#endregion
#region INotifyDataErrorInfo interface
event EventHandler<DataErrorsChangedEventArgs> INotifyDataErrorInfo.ErrorsChanged
{
add
{
ErrorsChanged += value;
}
remove
{
ErrorsChanged -= value;
}
}
/// <summary>
/// Gets the currently known errors for the provided property name. Use String.Empty/null
/// to retrieve entity-level errors.
/// </summary>
IEnumerable INotifyDataErrorInfo.GetErrors(string propertyName)
{
if (propertyName == null)
{
propertyName = string.Empty;
}
if (ValidationErrors.ContainsKey(propertyName))
{
return ValidationErrors[propertyName];
}
return null;
}
/// <summary>
/// Gets a value indicating whether there are known errors or not.
/// </summary>
bool INotifyDataErrorInfo.HasErrors
{
get
{
return ValidationErrors.Keys.Count != 0;
}
}
#endregion
#region INotifyDataErrorInfo Protected & Private Helper Methods
/// <summary>
/// Removes any known errors for the provided property name
/// by calling ClearErrors()
/// </summary>
/// <param name="propertyName">Propery name or String.Empty/null for top-level errors</param>
partial void PropertySetterEntry(string propertyName)
{
if (IsDeserializing || SuspendValidation)
{
return;
}
if (ValidateEntityOnPropertyChanged)
{
ClearErrors();
}
else
{
ClearErrors(propertyName);
}
}
/// <summary>
/// Validates for any known errors for the provided property name
/// </summary>
/// <param name="propertyName">Propery name or String.Empty/null for top-level errors</param>
/// <param name="propertyValue">Property value</param>
partial void PropertySetterExit(string propertyName, object propertyValue)
{
if (IsDeserializing || SuspendValidation)
{
return;
}
if (ValidateEntityOnPropertyChanged)
{
Validate(string.Empty, this);
}
else
{
Validate(propertyName, propertyValue);
}
}
#endregion
#region IEditableObject interface
private Dictionary<string , object> _cache;
public override void BeginEdit()
{
// call base BeginEdit() first
base.BeginEdit();
if (_cache == null) _cache = new Dictionary<string, object>();
// copy all Simple Properties except the primary key fields
_cache["EnrollmentDate"] = EnrollmentDate;
// copy all Navigation Properties
_cache["Enrollments"] = Enrollments;
}
public override void CancelEdit()
{
// call base CancelEdit() first
base.CancelEdit();
if (_cache == null) _cache = new Dictionary<string, object>();
if (_cache.Count == 0) return;
bool changeTrackingEnabled = ChangeTracker.ChangeTrackingEnabled;
this.StopTracking();
// copy all Simple Properties except the primary key fields
if (EnrollmentDate != (Nullable<System.DateTime>)_cache["EnrollmentDate"])
EnrollmentDate = (Nullable<System.DateTime>)_cache["EnrollmentDate"];
else
OnPropertyChanged("EnrollmentDate");
// copy all Navigation Properties
Enrollments = (TrackableCollection<Enrollment>)_cache["Enrollments"];
ChangeTracker.ChangeTrackingEnabled = changeTrackingEnabled;
_cache.Clear();
}
public override void EndEdit()
{
// call base EndEdit() first
base.EndEdit();
if (_cache == null) _cache = new Dictionary<string, object>();
_cache.Clear();
}
#endregion
}
}
#endif