This project is read-only.
Here's the definition for the Customers class mapped to the Customers table in Northwind:

 using System;
using System.Collections;
using System.Reflection;
using DataBroker.Dao;

namespace NorthwindDAO
{
	public class Customers : Entity
	{
		private String _CustomerID;
		private String _CompanyName;
		private String _ContactName;
		private String _ContactTitle;
		private String _Address;
		private String _City;
		private String _Region;
		private String _PostalCode;
		private String _Country;
		private String _Phone;
		private String _Fax;
	
		///Default constructor

		public Customers ()
		{
		
		}

        /// <summary>

        /// Constructor for joins. 

		/// Available CHILD tables to join with:

		///    - Customercustomerdemo ( Customercustomerdemo_fk_customercustomerdemo_customers )

		///    - Orders ( Orders_fk_orders_customers )

        /// </summary>

        public Customers(bool Flat, params Entity[] entities)
            : this()
		{
			foreach(Entity entity in entities)
			{
				string[] entityParts = entity.GetType().ToString().Split('.');
				string entityName = entityParts[entityParts.Length - 1];
				PropertyInfo pf = GetType().GetProperty((entityName));
				if (pf != null)
				{
					pf.SetValue(this,new EntityCollection(entity), null);
				}
                entityName = entityName + "_"; ;
                pf = GetType().GetProperty((entityName));
                if (pf != null)
                {
                    pf.SetValue(this, entity, null);
                }
			}
			SetFlat(Flat);
		}
        public Customers(params Entity[] entities)
            : this(true, entities)
		{
		}
	
		[IsNotNullable]
		[IsPK]
		[MaxLength(5)]
		public String Customerid
		{
			get
			{
				return _CustomerID;
			}
			set
			{
				_CustomerID = value;
			}
		}
		[IsNotNullable]
		[MaxLength(40)]
		public String Companyname
		{
			get
			{
				return _CompanyName;
			}
			set
			{
				_CompanyName = value;
			}
		}
		[MaxLength(30)]
		public String Contactname
		{
			get
			{
				return _ContactName;
			}
			set
			{
				_ContactName = value;
			}
		}
		[MaxLength(30)]
		public String Contacttitle
		{
			get
			{
				return _ContactTitle;
			}
			set
			{
				_ContactTitle = value;
			}
		}
		[MaxLength(60)]
		public String Address
		{
			get
			{
				return _Address;
			}
			set
			{
				_Address = value;
			}
		}
		[MaxLength(15)]
		public String City
		{
			get
			{
				return _City;
			}
			set
			{
				_City = value;
			}
		}
		[MaxLength(15)]
		public String Region
		{
			get
			{
				return _Region;
			}
			set
			{
				_Region = value;
			}
		}
		[MaxLength(10)]
		public String Postalcode
		{
			get
			{
				return _PostalCode;
			}
			set
			{
				_PostalCode = value;
			}
		}
		[MaxLength(15)]
		public String Country
		{
			get
			{
				return _Country;
			}
			set
			{
				_Country = value;
			}
		}
		[MaxLength(24)]
		public String Phone
		{
			get
			{
				return _Phone;
			}
			set
			{
				_Phone = value;
			}
		}
		[MaxLength(24)]
		public String Fax
		{
			get
			{
				return _Fax;
			}
			set
			{
				_Fax = value;
			}
		}
	
        #region Customercustomerdemo 
        private EntityCollection _Customercustomerdemo;
        [NotInTable]
        [TypeContained(typeof(Customercustomerdemo),"Customercustomerdemo")]
        public EntityCollection Customercustomerdemo
        {
            get
            {
                return _Customercustomerdemo;
            }

            set
            {
                _Customercustomerdemo = value;
            }
        }
        private Customercustomerdemo _Customercustomerdemo_;
        [NotInTable]
        public Customercustomerdemo Customercustomerdemo_
        {
            get
            {
                return _Customercustomerdemo_;
            }

            set
            {
                _Customercustomerdemo_ = value;
            }
        }
        #endregion
	
        #region Orders 
        private EntityCollection _Orders;
        [NotInTable]
        [TypeContained(typeof(Orders),"Orders")]
        public EntityCollection Orders
        {
            get
            {
                return _Orders;
            }

            set
            {
                _Orders = value;
            }
        }
        private Orders _Orders_;
        [NotInTable]
        public Orders Orders_
        {
            get
            {
                return _Orders_;
            }

            set
            {
                _Orders_ = value;
            }
        }
        #endregion
        public override DBJoin GetJoin(string tableName)
        {
			if (string.Compare(tableName, "Customercustomerdemo", true) == 0)
			{
				ArrayList left = new ArrayList();
				ArrayList right = new ArrayList();
				left.Add(tableName + ".Customerid");
				right.Add(GetType().Name + ".Customerid");
				return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
			}
			if (string.Compare(tableName, "Orders", true) == 0)
			{
				ArrayList left = new ArrayList();
				ArrayList right = new ArrayList();
				left.Add(tableName + ".Customerid");
				right.Add(GetType().Name + ".Customerid");
				return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
			}
			return null;
		}
	}
}  

Last edited Mar 2, 2009 at 2:26 AM by dbroker, version 2

Comments

No comments yet.