Click here to Skip to main content
15,891,644 members
Articles / Security

N - tier project with WCF OData service, Entity Framework, MVC3.0, Ninject DI, jSOn.net and Automapper

Rate me:
Please Sign up or sign in to vote.
4.62/5 (5 votes)
10 Dec 2012CPOL3 min read 39.6K   1.9K   41  
N-Tier application with WCF Odata service and Entity Framework.
//------------------------------------------------------------------------------
// <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.Collections.Specialized;
using System.Runtime.Serialization;

namespace eShopping.Entities.Entities
{
    [DataContract(IsReference = true)]
    [KnownType(typeof(Customer))]
    [KnownType(typeof(Order_Detail))]
    public partial class Order
    {
        #region Primitive Properties
        [DataMember]
        public virtual int OrderID
        {
            get;
            set;
        }
        [DataMember]
        public virtual string CustomerID
        {
            get { return _customerID; }
            set
            {
                try
                {
                    _settingFK = true;
                    if (_customerID != value)
                    {
                        if (Customer != null && Customer.CustomerID != value)
                        {
                            Customer = null;
                        }
                        _customerID = value;
                    }
                }
                finally
                {
                    _settingFK = false;
                }
            }
        }
        public string _customerID;
        [DataMember]
        public virtual Nullable<int> EmployeeID
        {
            get;
            set;
        }
        [DataMember]
        public virtual Nullable<System.DateTime> OrderDate
        {
            get;
            set;
        }
        [DataMember]
        public virtual Nullable<System.DateTime> RequiredDate
        {
            get;
            set;
        }
        [DataMember]
        public virtual Nullable<System.DateTime> ShippedDate
        {
            get;
            set;
        }
        [DataMember]
        public virtual Nullable<int> ShipVia
        {
            get;
            set;
        }
        [DataMember]
        public virtual Nullable<decimal> Freight
        {
            get;
            set;
        }
        [DataMember]
        public virtual string ShipName
        {
            get;
            set;
        }
        [DataMember]
        public virtual string ShipAddress
        {
            get;
            set;
        }
        [DataMember]
        public virtual string ShipCity
        {
            get;
            set;
        }
        [DataMember]
        public virtual string ShipRegion
        {
            get;
            set;
        }
        [DataMember]
        public virtual string ShipPostalCode
        {
            get;
            set;
        }
        [DataMember]
        public virtual string ShipCountry
        {
            get;
            set;
        }

        #endregion
        #region Navigation Properties
        
    
        [DataMember]
        public virtual Customer Customer
        {
            get { return _customer; }
            set
            {
                if (!ReferenceEquals(_customer, value))
                {
                    var previousValue = _customer;
                    _customer = value;
                    FixupCustomer(previousValue);
                }
            }
        }
        public Customer _customer;
        
    
        [DataMember]
        public virtual ICollection<Order_Detail> Order_Details
        {
            get
            {
                if (_order_Details == null)
                {
                    var newCollection = new FixupCollection<Order_Detail>();
                    newCollection.CollectionChanged += FixupOrder_Details;
                    _order_Details = newCollection;
                }
                return _order_Details;
            }
            set
            {
                if (!ReferenceEquals(_order_Details, value))
                {
                    var previousValue = _order_Details as FixupCollection<Order_Detail>;
                    if (previousValue != null)
                    {
                        previousValue.CollectionChanged -= FixupOrder_Details;
                    }
                    _order_Details = value;
                    var newValue = value as FixupCollection<Order_Detail>;
                    if (newValue != null)
                    {
                        newValue.CollectionChanged += FixupOrder_Details;
                    }
                }
            }
        }
        public ICollection<Order_Detail> _order_Details;

        #endregion
        #region Association Fixup
    
        public bool _settingFK = false;
    
        public void FixupCustomer(Customer previousValue)
        {
            if (previousValue != null && previousValue.Orders.Contains(this))
            {
                previousValue.Orders.Remove(this);
            }
    
            if (Customer != null)
            {
                if (!Customer.Orders.Contains(this))
                {
                    Customer.Orders.Add(this);
                }
                if (CustomerID != Customer.CustomerID)
                {
                    CustomerID = Customer.CustomerID;
                }
            }
            else if (!_settingFK)
            {
                CustomerID = null;
            }
        }
    
        public void FixupOrder_Details(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (Order_Detail item in e.NewItems)
                {
                    item.Order = this;
                }
            }
    
            if (e.OldItems != null)
            {
                foreach (Order_Detail item in e.OldItems)
                {
                    if (ReferenceEquals(item.Order, this))
                    {
                        item.Order = 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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Nagarro Softwares
India India
I am vijay tanwar and i am a software engineer with passion of programming. I love to programming in c#, I love to warp up more and more things in few lines of code. my favirote languages are c# and javascript and both are fully object oriended. I always like to become the .net Architect.

Comments and Discussions