Click here to Skip to main content
15,897,704 members
Articles / Programming Languages / C# 4.0

Relationship Oriented Programming - The IDE plus More on Agile Project Management

Rate me:
Please Sign up or sign in to vote.
4.98/5 (25 votes)
12 Mar 2012CPOL81 min read 78.6K   1.2K   49  
An Integrated Development Environment (IDE) for the Relationship Oriented Programming Tool.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

using Clifton.Tools.Strings;
using Clifton.Tools.Strings.Extensions;

using XTreeInterfaces;

namespace ROPLib
{
	public enum CardinalityEnum
	{
		OneToZeroOrOne,					// A can have 0 or 1 connections to B.
		OneToOne,						// requires a B.
		OneToMany,						// A can have 0...n connections to B.
		ManyToOne,						// B can have 1...n connections th A.
		ManyToMany,						// An association table is required to describe the relationship.
		ManyToZeroOrOne,				// Nullable FK.
	}

	public class Relationship : IHasCollection
	{
		[Category("Name")]
		[XmlAttribute()]
		public string Name { get; set; }

		/// <summary>
		/// The name of the "A" Entity
		/// </summary>
		[Category("Entities")]
		[TypeConverter(typeof(EntityNameConverter))]
		public string EntityA { get; set; }

		/// <summary>
		/// The name of the "B" Entity
		/// </summary>
		[Category("Entities")]
		[TypeConverter(typeof(EntityNameConverter))]
		public string EntityB { get; set; }

		/// <summary>
		/// The cardinality of the relationship of A to B
		/// </summary>
		[Category("Cardinality")]
		public CardinalityEnum AtoBCardinality { get; set; }

		/// <summary>
		/// The text describing the A to B relationship
		/// </summary>
		[Category("Relationship")]
		[Description("The text used to describe the A to B relationship.")]
		public string AtoBRelationship { get; set; }

		/// <summary>
		/// The text describing the B to A relationship
		/// </summary>
		[Category("Relationship")]
		[Description("The text used to describe the B to A relationship.")]
		public string BtoARelationship { get; set; }

		[Category("Attributes")]
		[TypeConverter(typeof(EntityNameConverter))]
		[Description("The relationship itself can have attributes that are described by an Entity.")]
		[XmlAttribute()]
		public string DescribedWith { get; set; }

		[Category("Schema")]
		[Description("The attribute in Entity A that is the foreign key to a primary key attribute in Entity B.")]
		[XmlAttribute()]
		[TypeConverter(typeof(EntityAttributesConverter))]
		public string ForeignKeyAttribute { get; set; }

		[XmlIgnore]
		[Browsable(false)]
		public Dictionary<string, dynamic> Collection { get; protected set; }

		[Browsable(false)]
		public List<RelationshipTypes> RelationshipTypes { get; set; }

		[Browsable(false)]
		public string Label { get { return Name.Brace() + "\\n" + AtoBRelationship + " /\\n" + BtoARelationship; } }

		[Browsable(false)]
		public string CardinalityALabel { get { return CardinalityALabels[(int)AtoBCardinality]; } }

		[Browsable(false)]
		public string CardinalityBLabel { get { return CardinalityBLabels[(int)AtoBCardinality]; } }

		protected string[] CardinalityALabels = { "1", "1", "1", "n", "m", "n" };
		protected string[] CardinalityBLabels = { "0,1", "1", "n", "1", "n", "0,1" };

		public Relationship()
		{
			DescribedWith = String.Empty;
			ForeignKeyAttribute = String.Empty;
			RelationshipTypes = new List<RelationshipTypes>();

			Collection = new Dictionary<string, dynamic>() { 
				{"RelationshipTypes", RelationshipTypes},
			};
		}
	}
}

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
Architect Interacx
United States United States
Blog: https://marcclifton.wordpress.com/
Home Page: http://www.marcclifton.com
Research: http://www.higherorderprogramming.com/
GitHub: https://github.com/cliftonm

All my life I have been passionate about architecture / software design, as this is the cornerstone to a maintainable and extensible application. As such, I have enjoyed exploring some crazy ideas and discovering that they are not so crazy after all. I also love writing about my ideas and seeing the community response. As a consultant, I've enjoyed working in a wide range of industries such as aerospace, boatyard management, remote sensing, emergency services / data management, and casino operations. I've done a variety of pro-bono work non-profit organizations related to nature conservancy, drug recovery and women's health.

Comments and Discussions