//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.4005
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace SilverlightGridHierarchyUsingMVVMAndServices
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Web.Ria.Data;
    using System.Windows.Ria.Data;
    
    
    /// <summary>
    /// Context for the RIA application.
    /// </summary>
    /// <remarks>
    /// This context extends the base to make application services and types available
    /// for consumption from code and xaml.
    /// </remarks>
    public sealed partial class RiaContext : System.Windows.Ria.RiaContextBase
    {
        
        #region Extensibility Method Definitions

        /// <summary>
        /// This method is invoked from the constructor once initialization is complete and
        /// can be used for further object setup.
        /// </summary>
        partial void OnCreated();

        #endregion
        
        
        /// <summary>
        /// Initializes a new instance of the RiaContext class.
        /// </summary>
        public RiaContext()
        {
            this.OnCreated();
        }
        
        /// <summary>
        /// Gets the context that is registered as a lifetime object with the current application.
        /// </summary>
        /// <exception cref="InvalidOperationException"> is thrown if there is no current application,
        /// no contexts have been added, or more than one context has been added.
        /// </exception>
        /// <seealso cref="Application.ApplicationLifetimeObjects"/>
        public new static RiaContext Current
        {
            get
            {
                return ((RiaContext)(System.Windows.Ria.RiaContextBase.Current));
            }
        }
    }
}
namespace SilverlightGridHierarchyUsingMVVMAndServices.Web
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.Web.Ria.Data;
    using System.Windows.Ria.Data;
    
    
    [DataContract(Namespace="http://schemas.datacontract.org/2004/07/SilverlightGridHierarchyUsingMVVMAndServi" +
        "ces.Web")]
    public sealed partial class Customer : Entity
    {
        
        private string _address;
        
        private string _city;
        
        private string _companyName;
        
        private string _contactName;
        
        private string _contactTitle;
        
        private string _country;
        
        private string _customerID;
        
        private string _fax;
        
        private EntityCollection<Order> _orders;
        
        private string _phone;
        
        private string _postalCode;
        
        private string _region;
        
        #region Extensibility Method Definitions

        /// <summary>
        /// This method is invoked from the constructor once initialization is complete and
        /// can be used for further object setup.
        /// </summary>
        partial void OnCreated();
        partial void OnAddressChanging(string value);
        partial void OnAddressChanged();
        partial void OnCityChanging(string value);
        partial void OnCityChanged();
        partial void OnCompanyNameChanging(string value);
        partial void OnCompanyNameChanged();
        partial void OnContactNameChanging(string value);
        partial void OnContactNameChanged();
        partial void OnContactTitleChanging(string value);
        partial void OnContactTitleChanged();
        partial void OnCountryChanging(string value);
        partial void OnCountryChanged();
        partial void OnCustomerIDChanging(string value);
        partial void OnCustomerIDChanged();
        partial void OnFaxChanging(string value);
        partial void OnFaxChanged();
        partial void OnPhoneChanging(string value);
        partial void OnPhoneChanged();
        partial void OnPostalCodeChanging(string value);
        partial void OnPostalCodeChanged();
        partial void OnRegionChanging(string value);
        partial void OnRegionChanged();

        #endregion
        
        
        /// <summary>
        /// Default constructor.
        /// </summary>
        public Customer()
        {
            this.OnCreated();
        }
        
        [DataMember()]
        [StringLength(60)]
        public string Address
        {
            get
            {
                return this._address;
            }
            set
            {
                if ((this._address != value))
                {
                    this.ValidateProperty("Address", value);
                    this.OnAddressChanging(value);
                    this.RaiseDataMemberChanging("Address");
                    this._address = value;
                    this.RaiseDataMemberChanged("Address");
                    this.OnAddressChanged();
                }
            }
        }
        
        [DataMember()]
        [StringLength(15)]
        public string City
        {
            get
            {
                return this._city;
            }
            set
            {
                if ((this._city != value))
                {
                    this.ValidateProperty("City", value);
                    this.OnCityChanging(value);
                    this.RaiseDataMemberChanging("City");
                    this._city = value;
                    this.RaiseDataMemberChanged("City");
                    this.OnCityChanged();
                }
            }
        }
        
        [DataMember()]
        [StringLength(40)]
        public string CompanyName
        {
            get
            {
                return this._companyName;
            }
            set
            {
                if ((this._companyName != value))
                {
                    this.ValidateProperty("CompanyName", value);
                    this.OnCompanyNameChanging(value);
                    this.RaiseDataMemberChanging("CompanyName");
                    this._companyName = value;
                    this.RaiseDataMemberChanged("CompanyName");
                    this.OnCompanyNameChanged();
                }
            }
        }
        
        [DataMember()]
        [StringLength(30)]
        public string ContactName
        {
            get
            {
                return this._contactName;
            }
            set
            {
                if ((this._contactName != value))
                {
                    this.ValidateProperty("ContactName", value);
                    this.OnContactNameChanging(value);
                    this.RaiseDataMemberChanging("ContactName");
                    this._contactName = value;
                    this.RaiseDataMemberChanged("ContactName");
                    this.OnContactNameChanged();
                }
            }
        }
        
        [DataMember()]
        [StringLength(30)]
        public string ContactTitle
        {
            get
            {
                return this._contactTitle;
            }
            set
            {
                if ((this._contactTitle != value))
                {
                    this.ValidateProperty("ContactTitle", value);
                    this.OnContactTitleChanging(value);
                    this.RaiseDataMemberChanging("ContactTitle");
                    this._contactTitle = value;
                    this.RaiseDataMemberChanged("ContactTitle");
                    this.OnContactTitleChanged();
                }
            }
        }
        
        [DataMember()]
        [StringLength(15)]
        public string Country
        {
            get
            {
                return this._country;
            }
            set
            {
                if ((this._country != value))
                {
                    this.ValidateProperty("Country", value);
                    this.OnCountryChanging(value);
                    this.RaiseDataMemberChanging("Country");
                    this._country = value;
                    this.RaiseDataMemberChanged("Country");
                    this.OnCountryChanged();
                }
            }
        }
        
        [DataMember()]
        [Key()]
        [StringLength(5)]
        public string CustomerID
        {
            get
            {
                return this._customerID;
            }
            set
            {
                if ((this._customerID != value))
                {
                    this.ValidateProperty("CustomerID", value);
                    this.OnCustomerIDChanging(value);
                    this.RaiseDataMemberChanging("CustomerID");
                    this._customerID = value;
                    this.RaiseDataMemberChanged("CustomerID");
                    this.OnCustomerIDChanged();
                }
            }
        }
        
        [DataMember()]
        [StringLength(24)]
        public string Fax
        {
            get
            {
                return this._fax;
            }
            set
            {
                if ((this._fax != value))
                {
                    this.ValidateProperty("Fax", value);
                    this.OnFaxChanging(value);
                    this.RaiseDataMemberChanging("Fax");
                    this._fax = value;
                    this.RaiseDataMemberChanged("Fax");
                    this.OnFaxChanged();
                }
            }
        }
        
        [Association("Customer_Order", "CustomerID", "CustomerID")]
        public EntityCollection<Order> Orders
        {
            get
            {
                if ((this._orders == null))
                {
                    this._orders = new EntityCollection<Order>(this, "Orders", this.FilterOrders, this.AttachOrders, this.DetachOrders);
                }
                return this._orders;
            }
        }
        
        [DataMember()]
        [StringLength(24)]
        public string Phone
        {
            get
            {
                return this._phone;
            }
            set
            {
                if ((this._phone != value))
                {
                    this.ValidateProperty("Phone", value);
                    this.OnPhoneChanging(value);
                    this.RaiseDataMemberChanging("Phone");
                    this._phone = value;
                    this.RaiseDataMemberChanged("Phone");
                    this.OnPhoneChanged();
                }
            }
        }
        
        [DataMember()]
        [StringLength(10)]
        public string PostalCode
        {
            get
            {
                return this._postalCode;
            }
            set
            {
                if ((this._postalCode != value))
                {
                    this.ValidateProperty("PostalCode", value);
                    this.OnPostalCodeChanging(value);
                    this.RaiseDataMemberChanging("PostalCode");
                    this._postalCode = value;
                    this.RaiseDataMemberChanged("PostalCode");
                    this.OnPostalCodeChanged();
                }
            }
        }
        
        [DataMember()]
        [StringLength(15)]
        public string Region
        {
            get
            {
                return this._region;
            }
            set
            {
                if ((this._region != value))
                {
                    this.ValidateProperty("Region", value);
                    this.OnRegionChanging(value);
                    this.RaiseDataMemberChanging("Region");
                    this._region = value;
                    this.RaiseDataMemberChanged("Region");
                    this.OnRegionChanged();
                }
            }
        }
        
        private void AttachOrders(Order entity)
        {
            entity.Customer = this;
        }
        
        private void DetachOrders(Order entity)
        {
            entity.Customer = null;
        }
        
        private bool FilterOrders(Order entity)
        {
            return (entity.CustomerID == this.CustomerID);
        }
        
        public override object GetIdentity()
        {
            return this._customerID;
        }
    }
    
    public sealed partial class NorthwindDomainContext : DomainContext
    {
        
        #region Extensibility Method Definitions

        /// <summary>
        /// This method is invoked from the constructor once initialization is complete and
        /// can be used for further object setup.
        /// </summary>
        partial void OnCreated();

        #endregion
        
        
        /// <summary>
        /// Default constructor.
        /// </summary>
        public NorthwindDomainContext() : 
                this(new HttpDomainClient(new Uri("DataService.axd/SilverlightGridHierarchyUsingMVVMAndServices-Web-NorthwindDomainS" +
                                "ervice/", System.UriKind.Relative)))
        {
        }
        
        /// <summary>
        /// Constructor used to specify a data service URI.
        /// </summary>
        /// <param name="serviceUri">
        /// The NorthwindDomainService data service URI.
        /// </param>
        public NorthwindDomainContext(Uri serviceUri) : 
                this(new HttpDomainClient(serviceUri))
        {
        }
        
        /// <summary>
        /// Constructor used to specify a DomainClient instance.
        /// </summary>
        /// <param name="domainClient">
        /// The DomainClient instance the DomainContext should use.
        /// </param>
        public NorthwindDomainContext(DomainClient domainClient) : 
                base(domainClient)
        {
            this.OnCreated();
        }
        
        public EntityList<Customer> Customers
        {
            get
            {
                return base.Entities.GetEntityList<Customer>();
            }
        }
        
        public EntityList<Order_Detail> Order_Details
        {
            get
            {
                return base.Entities.GetEntityList<Order_Detail>();
            }
        }
        
        public EntityList<Order> Orders
        {
            get
            {
                return base.Entities.GetEntityList<Order>();
            }
        }
        
        /// <summary>
        /// Returns an EntityQuery for query operation 'GetCustomers'.
        /// </summary>
        public EntityQuery<Customer> GetCustomersQuery()
        {
            return base.CreateQuery<Customer>("GetCustomers", null, false, true);
        }
        
        /// <summary>
        /// Returns an EntityQuery for query operation 'GetOrder_Details'.
        /// </summary>
        public EntityQuery<Order_Detail> GetOrder_DetailsQuery()
        {
            return base.CreateQuery<Order_Detail>("GetOrder_Details", null, false, true);
        }
        
        /// <summary>
        /// Returns an EntityQuery for query operation 'GetOrders'.
        /// </summary>
        public EntityQuery<Order> GetOrdersQuery()
        {
            return base.CreateQuery<Order>("GetOrders", null, false, true);
        }
        
        protected override EntityContainer CreateEntityContainer()
        {
            return new NorthwindDomainContextEntityContainer();
        }
        
        internal sealed class NorthwindDomainContextEntityContainer : EntityContainer
        {
            
            public NorthwindDomainContextEntityContainer()
            {
                this.CreateEntityList<Customer>(EntityListOperations.None);
                this.CreateEntityList<Order>(EntityListOperations.None);
                this.CreateEntityList<Order_Detail>(EntityListOperations.None);
            }
        }
    }
    
    [DataContract(Namespace="http://schemas.datacontract.org/2004/07/SilverlightGridHierarchyUsingMVVMAndServi" +
        "ces.Web")]
    public sealed partial class Order : Entity
    {
        
        private EntityRef<Customer> _customer;
        
        private string _customerID;
        
        private Nullable<int> _employeeID;
        
        private Nullable<decimal> _freight;
        
        private EntityCollection<Order_Detail> _order_Details;
        
        private Nullable<DateTime> _orderDate;
        
        private int _orderID;
        
        private Nullable<DateTime> _requiredDate;
        
        private string _shipAddress;
        
        private string _shipCity;
        
        private string _shipCountry;
        
        private string _shipName;
        
        private Nullable<DateTime> _shippedDate;
        
        private string _shipPostalCode;
        
        private string _shipRegion;
        
        private Nullable<int> _shipVia;
        
        #region Extensibility Method Definitions

        /// <summary>
        /// This method is invoked from the constructor once initialization is complete and
        /// can be used for further object setup.
        /// </summary>
        partial void OnCreated();
        partial void OnCustomerIDChanging(string value);
        partial void OnCustomerIDChanged();
        partial void OnEmployeeIDChanging(Nullable<int> value);
        partial void OnEmployeeIDChanged();
        partial void OnFreightChanging(Nullable<decimal> value);
        partial void OnFreightChanged();
        partial void OnOrderDateChanging(Nullable<DateTime> value);
        partial void OnOrderDateChanged();
        partial void OnOrderIDChanging(int value);
        partial void OnOrderIDChanged();
        partial void OnRequiredDateChanging(Nullable<DateTime> value);
        partial void OnRequiredDateChanged();
        partial void OnShipAddressChanging(string value);
        partial void OnShipAddressChanged();
        partial void OnShipCityChanging(string value);
        partial void OnShipCityChanged();
        partial void OnShipCountryChanging(string value);
        partial void OnShipCountryChanged();
        partial void OnShipNameChanging(string value);
        partial void OnShipNameChanged();
        partial void OnShippedDateChanging(Nullable<DateTime> value);
        partial void OnShippedDateChanged();
        partial void OnShipPostalCodeChanging(string value);
        partial void OnShipPostalCodeChanged();
        partial void OnShipRegionChanging(string value);
        partial void OnShipRegionChanged();
        partial void OnShipViaChanging(Nullable<int> value);
        partial void OnShipViaChanged();

        #endregion
        
        
        /// <summary>
        /// Default constructor.
        /// </summary>
        public Order()
        {
            this.OnCreated();
        }
        
        [Association("Customer_Order", "CustomerID", "CustomerID", IsForeignKey=true)]
        public Customer Customer
        {
            get
            {
                if ((this._customer == null))
                {
                    this._customer = new EntityRef<Customer>(this, "Customer", this.FilterCustomer);
                }
                return this._customer.Entity;
            }
            set
            {
                Customer previous = this.Customer;
                if ((previous != value))
                {
                    this.ValidateProperty("Customer", value);
                    if ((previous != null))
                    {
                        this._customer.Entity = null;
                        previous.Orders.Remove(this);
                    }
                    this._customer.Entity = value;
                    if ((value != null))
                    {
                        value.Orders.Add(this);
                        this.CustomerID = value.CustomerID;
                    }
                    else
                    {
                        this.CustomerID = default(string);
                    }
                    this.RaisePropertyChanged("Customer");
                }
            }
        }
        
        [DataMember()]
        [StringLength(5)]
        public string CustomerID
        {
            get
            {
                return this._customerID;
            }
            set
            {
                if ((this._customerID != value))
                {
                    this.ValidateProperty("CustomerID", value);
                    this.OnCustomerIDChanging(value);
                    this.RaiseDataMemberChanging("CustomerID");
                    this._customerID = value;
                    this.RaiseDataMemberChanged("CustomerID");
                    this.OnCustomerIDChanged();
                }
            }
        }
        
        [DataMember()]
        public Nullable<int> EmployeeID
        {
            get
            {
                return this._employeeID;
            }
            set
            {
                if ((this._employeeID != value))
                {
                    this.ValidateProperty("EmployeeID", value);
                    this.OnEmployeeIDChanging(value);
                    this.RaiseDataMemberChanging("EmployeeID");
                    this._employeeID = value;
                    this.RaiseDataMemberChanged("EmployeeID");
                    this.OnEmployeeIDChanged();
                }
            }
        }
        
        [DataMember()]
        public Nullable<decimal> Freight
        {
            get
            {
                return this._freight;
            }
            set
            {
                if ((this._freight != value))
                {
                    this.ValidateProperty("Freight", value);
                    this.OnFreightChanging(value);
                    this.RaiseDataMemberChanging("Freight");
                    this._freight = value;
                    this.RaiseDataMemberChanged("Freight");
                    this.OnFreightChanged();
                }
            }
        }
        
        [Association("Order_Order_Detail", "OrderID", "OrderID")]
        public EntityCollection<Order_Detail> Order_Details
        {
            get
            {
                if ((this._order_Details == null))
                {
                    this._order_Details = new EntityCollection<Order_Detail>(this, "Order_Details", this.FilterOrder_Details, this.AttachOrder_Details, this.DetachOrder_Details);
                }
                return this._order_Details;
            }
        }
        
        [DataMember()]
        public Nullable<DateTime> OrderDate
        {
            get
            {
                return this._orderDate;
            }
            set
            {
                if ((this._orderDate != value))
                {
                    this.ValidateProperty("OrderDate", value);
                    this.OnOrderDateChanging(value);
                    this.RaiseDataMemberChanging("OrderDate");
                    this._orderDate = value;
                    this.RaiseDataMemberChanged("OrderDate");
                    this.OnOrderDateChanged();
                }
            }
        }
        
        [DataMember()]
        [Key()]
        public int OrderID
        {
            get
            {
                return this._orderID;
            }
            set
            {
                if ((this._orderID != value))
                {
                    this.ValidateProperty("OrderID", value);
                    this.OnOrderIDChanging(value);
                    this.RaiseDataMemberChanging("OrderID");
                    this._orderID = value;
                    this.RaiseDataMemberChanged("OrderID");
                    this.OnOrderIDChanged();
                }
            }
        }
        
        [DataMember()]
        public Nullable<DateTime> RequiredDate
        {
            get
            {
                return this._requiredDate;
            }
            set
            {
                if ((this._requiredDate != value))
                {
                    this.ValidateProperty("RequiredDate", value);
                    this.OnRequiredDateChanging(value);
                    this.RaiseDataMemberChanging("RequiredDate");
                    this._requiredDate = value;
                    this.RaiseDataMemberChanged("RequiredDate");
                    this.OnRequiredDateChanged();
                }
            }
        }
        
        [DataMember()]
        [StringLength(60)]
        public string ShipAddress
        {
            get
            {
                return this._shipAddress;
            }
            set
            {
                if ((this._shipAddress != value))
                {
                    this.ValidateProperty("ShipAddress", value);
                    this.OnShipAddressChanging(value);
                    this.RaiseDataMemberChanging("ShipAddress");
                    this._shipAddress = value;
                    this.RaiseDataMemberChanged("ShipAddress");
                    this.OnShipAddressChanged();
                }
            }
        }
        
        [DataMember()]
        [StringLength(15)]
        public string ShipCity
        {
            get
            {
                return this._shipCity;
            }
            set
            {
                if ((this._shipCity != value))
                {
                    this.ValidateProperty("ShipCity", value);
                    this.OnShipCityChanging(value);
                    this.RaiseDataMemberChanging("ShipCity");
                    this._shipCity = value;
                    this.RaiseDataMemberChanged("ShipCity");
                    this.OnShipCityChanged();
                }
            }
        }
        
        [DataMember()]
        [StringLength(15)]
        public string ShipCountry
        {
            get
            {
                return this._shipCountry;
            }
            set
            {
                if ((this._shipCountry != value))
                {
                    this.ValidateProperty("ShipCountry", value);
                    this.OnShipCountryChanging(value);
                    this.RaiseDataMemberChanging("ShipCountry");
                    this._shipCountry = value;
                    this.RaiseDataMemberChanged("ShipCountry");
                    this.OnShipCountryChanged();
                }
            }
        }
        
        [DataMember()]
        [StringLength(40)]
        public string ShipName
        {
            get
            {
                return this._shipName;
            }
            set
            {
                if ((this._shipName != value))
                {
                    this.ValidateProperty("ShipName", value);
                    this.OnShipNameChanging(value);
                    this.RaiseDataMemberChanging("ShipName");
                    this._shipName = value;
                    this.RaiseDataMemberChanged("ShipName");
                    this.OnShipNameChanged();
                }
            }
        }
        
        [DataMember()]
        public Nullable<DateTime> ShippedDate
        {
            get
            {
                return this._shippedDate;
            }
            set
            {
                if ((this._shippedDate != value))
                {
                    this.ValidateProperty("ShippedDate", value);
                    this.OnShippedDateChanging(value);
                    this.RaiseDataMemberChanging("ShippedDate");
                    this._shippedDate = value;
                    this.RaiseDataMemberChanged("ShippedDate");
                    this.OnShippedDateChanged();
                }
            }
        }
        
        [DataMember()]
        [StringLength(10)]
        public string ShipPostalCode
        {
            get
            {
                return this._shipPostalCode;
            }
            set
            {
                if ((this._shipPostalCode != value))
                {
                    this.ValidateProperty("ShipPostalCode", value);
                    this.OnShipPostalCodeChanging(value);
                    this.RaiseDataMemberChanging("ShipPostalCode");
                    this._shipPostalCode = value;
                    this.RaiseDataMemberChanged("ShipPostalCode");
                    this.OnShipPostalCodeChanged();
                }
            }
        }
        
        [DataMember()]
        [StringLength(15)]
        public string ShipRegion
        {
            get
            {
                return this._shipRegion;
            }
            set
            {
                if ((this._shipRegion != value))
                {
                    this.ValidateProperty("ShipRegion", value);
                    this.OnShipRegionChanging(value);
                    this.RaiseDataMemberChanging("ShipRegion");
                    this._shipRegion = value;
                    this.RaiseDataMemberChanged("ShipRegion");
                    this.OnShipRegionChanged();
                }
            }
        }
        
        [DataMember()]
        public Nullable<int> ShipVia
        {
            get
            {
                return this._shipVia;
            }
            set
            {
                if ((this._shipVia != value))
                {
                    this.ValidateProperty("ShipVia", value);
                    this.OnShipViaChanging(value);
                    this.RaiseDataMemberChanging("ShipVia");
                    this._shipVia = value;
                    this.RaiseDataMemberChanged("ShipVia");
                    this.OnShipViaChanged();
                }
            }
        }
        
        private bool FilterCustomer(Customer entity)
        {
            return (entity.CustomerID == this.CustomerID);
        }
        
        private void AttachOrder_Details(Order_Detail entity)
        {
            entity.Order = this;
        }
        
        private void DetachOrder_Details(Order_Detail entity)
        {
            entity.Order = null;
        }
        
        private bool FilterOrder_Details(Order_Detail entity)
        {
            return (entity.OrderID == this.OrderID);
        }
        
        public override object GetIdentity()
        {
            return this._orderID;
        }
    }
    
    [DataContract(Namespace="http://schemas.datacontract.org/2004/07/SilverlightGridHierarchyUsingMVVMAndServi" +
        "ces.Web")]
    public sealed partial class Order_Detail : Entity
    {
        
        private float _discount;
        
        private EntityRef<Order> _order;
        
        private int _orderID;
        
        private int _productID;
        
        private short _quantity;
        
        private decimal _unitPrice;
        
        #region Extensibility Method Definitions

        /// <summary>
        /// This method is invoked from the constructor once initialization is complete and
        /// can be used for further object setup.
        /// </summary>
        partial void OnCreated();
        partial void OnDiscountChanging(float value);
        partial void OnDiscountChanged();
        partial void OnOrderIDChanging(int value);
        partial void OnOrderIDChanged();
        partial void OnProductIDChanging(int value);
        partial void OnProductIDChanged();
        partial void OnQuantityChanging(short value);
        partial void OnQuantityChanged();
        partial void OnUnitPriceChanging(decimal value);
        partial void OnUnitPriceChanged();

        #endregion
        
        
        /// <summary>
        /// Default constructor.
        /// </summary>
        public Order_Detail()
        {
            this.OnCreated();
        }
        
        [DataMember()]
        public float Discount
        {
            get
            {
                return this._discount;
            }
            set
            {
                if ((this._discount != value))
                {
                    this.ValidateProperty("Discount", value);
                    this.OnDiscountChanging(value);
                    this.RaiseDataMemberChanging("Discount");
                    this._discount = value;
                    this.RaiseDataMemberChanged("Discount");
                    this.OnDiscountChanged();
                }
            }
        }
        
        [Association("Order_Order_Detail", "OrderID", "OrderID", IsForeignKey=true)]
        public Order Order
        {
            get
            {
                if ((this._order == null))
                {
                    this._order = new EntityRef<Order>(this, "Order", this.FilterOrder);
                }
                return this._order.Entity;
            }
            set
            {
                Order previous = this.Order;
                if ((previous != value))
                {
                    this.ValidateProperty("Order", value);
                    if ((previous != null))
                    {
                        this._order.Entity = null;
                        previous.Order_Details.Remove(this);
                    }
                    this._order.Entity = value;
                    if ((value != null))
                    {
                        value.Order_Details.Add(this);
                        this.OrderID = value.OrderID;
                    }
                    else
                    {
                        this.OrderID = default(int);
                    }
                    this.RaisePropertyChanged("Order");
                }
            }
        }
        
        [DataMember()]
        [Key()]
        public int OrderID
        {
            get
            {
                return this._orderID;
            }
            set
            {
                if ((this._orderID != value))
                {
                    this.ValidateProperty("OrderID", value);
                    this.OnOrderIDChanging(value);
                    this.RaiseDataMemberChanging("OrderID");
                    this._orderID = value;
                    this.RaiseDataMemberChanged("OrderID");
                    this.OnOrderIDChanged();
                }
            }
        }
        
        [DataMember()]
        [Key()]
        public int ProductID
        {
            get
            {
                return this._productID;
            }
            set
            {
                if ((this._productID != value))
                {
                    this.ValidateProperty("ProductID", value);
                    this.OnProductIDChanging(value);
                    this.RaiseDataMemberChanging("ProductID");
                    this._productID = value;
                    this.RaiseDataMemberChanged("ProductID");
                    this.OnProductIDChanged();
                }
            }
        }
        
        [DataMember()]
        public short Quantity
        {
            get
            {
                return this._quantity;
            }
            set
            {
                if ((this._quantity != value))
                {
                    this.ValidateProperty("Quantity", value);
                    this.OnQuantityChanging(value);
                    this.RaiseDataMemberChanging("Quantity");
                    this._quantity = value;
                    this.RaiseDataMemberChanged("Quantity");
                    this.OnQuantityChanged();
                }
            }
        }
        
        [DataMember()]
        public decimal UnitPrice
        {
            get
            {
                return this._unitPrice;
            }
            set
            {
                if ((this._unitPrice != value))
                {
                    this.ValidateProperty("UnitPrice", value);
                    this.OnUnitPriceChanging(value);
                    this.RaiseDataMemberChanging("UnitPrice");
                    this._unitPrice = value;
                    this.RaiseDataMemberChanged("UnitPrice");
                    this.OnUnitPriceChanged();
                }
            }
        }
        
        private bool FilterOrder(Order entity)
        {
            return (entity.OrderID == this.OrderID);
        }
        
        public override object GetIdentity()
        {
            return EntityKey.Create(this._orderID, this._productID);
        }
    }
}
