|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using Demo.Base;
using System.ComponentModel.DataAnnotations;
namespace Demo.Models.Domain
{
public partial class Customer
{
#region Primitive Properties
public virtual string CustomerID
{
get;
set;
}
[Required]
public virtual string CompanyName
{
get;
set;
}
public virtual string ContactName
{
get;
set;
}
public virtual string ContactTitle
{
get;
set;
}
public virtual string Address
{
get;
set;
}
public virtual string City
{
get;
set;
}
public virtual string Region
{
get;
set;
}
public virtual string PostalCode
{
get;
set;
}
public virtual string Country
{
get;
set;
}
public virtual string Phone
{
get;
set;
}
public virtual string Fax
{
get;
set;
}
#endregion
#region Navigation Properties
public virtual ICollection<Order> Orders
{
get
{
if (_orders == null)
{
var newCollection = new FixupCollection<Order>();
newCollection.CollectionChanged += FixupOrders;
_orders = newCollection;
}
return _orders;
}
set
{
if (!ReferenceEquals(_orders, value))
{
var previousValue = _orders as FixupCollection<Order>;
if (previousValue != null)
{
previousValue.CollectionChanged -= FixupOrders;
}
_orders = value;
var newValue = value as FixupCollection<Order>;
if (newValue != null)
{
newValue.CollectionChanged += FixupOrders;
}
}
}
}
private ICollection<Order> _orders;
#endregion
#region Association Fixup
private void FixupOrders(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.NewItems != null)
{
foreach (Order item in e.NewItems)
{
item.Customer = this;
}
}
if (e.OldItems != null)
{
foreach (Order item in e.OldItems)
{
if (ReferenceEquals(item.Customer, this))
{
item.Customer = null;
}
}
}
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.