Click here to Skip to main content
15,893,644 members
Articles / Web Development / ASP.NET

Developing Web Applications with ASP.NET MVC3 and Entity Framework 4.1

Rate me:
Please Sign up or sign in to vote.
4.82/5 (4 votes)
17 Aug 2011CPOL5 min read 106.6K   4.4K   50  
In this article, I will provide a demo application that is developed with the ASP.NET MVC3 and Entity Framework4.1.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;

namespace Demo.Models.Domain
{
    public partial class Order
    {
        #region Primitive Properties
    
        public virtual int OrderID
        {
            get;
            set;
        }
    
        public virtual Nullable<System.DateTime> OrderDate
        {
            get;
            set;
        }
    
        public virtual Nullable<System.DateTime> RequiredDate
        {
            get;
            set;
        }
    
        public virtual Nullable<System.DateTime> ShippedDate
        {
            get;
            set;
        }
    
        public virtual Nullable<decimal> Freight
        {
            get;
            set;
        }
    
        public virtual string ShipName
        {
            get;
            set;
        }
    
        public virtual string ShipAddress
        {
            get;
            set;
        }
    
        public virtual string ShipCity
        {
            get;
            set;
        }
    
        public virtual string ShipRegion
        {
            get;
            set;
        }
    
        public virtual string ShipPostalCode
        {
            get;
            set;
        }
    
        public virtual string ShipCountry
        {
            get;
            set;
        }

        #endregion
        #region Navigation Properties
    
        public virtual Customer Customer
        {
            get { return _customer; }
            set
            {
                if (!ReferenceEquals(_customer, value))
                {
                    var previousValue = _customer;
                    _customer = value;
                    FixupCustomer(previousValue);
                }
            }
        }
        private Customer _customer;

        #endregion
        #region Association Fixup
    
        private 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);
                }
            }
        }

        #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)
United States United States
Senior Software Developer from New Jersey, USA

Have 15+ years experience on enterprise application development with various technologies.

Comments and Discussions