示例#1
0
        private void GenerateSingletonAssociationPropertyGetter(AssociationMetadata metadata)
        {
            string returnType = metadata.FieldName;

            if (!metadata.IsCollection)
            {
                returnType = returnType + ".Entity";
            }

            this.Write("get\r\n{\r\n\tif(this.");

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

            this.Write(" == null)\r\n\t{\r\n\t\tthis.");

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

            this.Write(" = new ");

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.AssociationTypeName));

            this.Write("(this, \"");

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyName));

            this.Write("\", this.Filter");

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyName));

            this.Write(");\r\n\t}\r\n\treturn this.");

            this.Write(this.ToStringHelper.ToStringWithCulture(returnType));

            this.Write(";\r\n}\r\n");
        }
示例#2
0
        private void GenerateSingletonAssociationPropertySetterEntitySetStatement(AssociationMetadata metadata, bool isBiDirectionalAssociation, bool reverseIsSingleton, string revName)
        {
            this.Write("this.");

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

            this.Write(".Entity = value;\r\n");


            if (isBiDirectionalAssociation)
            {
                this.Write("if(value != null)\r\n");


                this.GenerateOpeningBrace();
                if (!reverseIsSingleton)
                {
                    this.Write("value.");

                    this.Write(this.ToStringHelper.ToStringWithCulture(revName));

                    this.Write(".Add(this);\r\n");
                }
                else
                {
                    this.Write("value.");

                    this.Write(this.ToStringHelper.ToStringWithCulture(revName));

                    this.Write(" = this;\r\n");
                }
                this.GenerateClosingBrace();
            }
        }
示例#3
0
        private void GenerateCollectionSideAssociation(PropertyDescriptor pd)
        {
            AssociationMetadata metadata = new AssociationMetadata(pd);

            this.GenerateAssociationField(metadata);
            this.GenerateCollectionAssociationProperty(metadata);
            this.GenerateAssociationFilterMethod(metadata);
        }
示例#4
0
 private void GenerateSingletonAssociationProperty(AssociationMetadata metadata)
 {
     this.GenerateAssociationPropertyDeclaration(metadata);
     this.GenerateOpeningBrace();
     this.GenerateSingletonAssociationPropertyGetter(metadata);
     this.GenerateSingletonAssociationPropertySetter(metadata);
     this.GenerateClosingBrace();
 }
示例#5
0
        private void GenerateAssociationField(AssociationMetadata metadata)
        {
            this.Write("private ");

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.AssociationTypeName));

            this.Write(" ");

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

            this.Write(";\r\n");
        }
示例#6
0
        private void GenerateCollectionAssociationProperty(AssociationMetadata metadata)
        {
            this.GenerateAssociationPropertyDeclaration(metadata);
            this.GenerateOpeningBrace();
            bool isBiDirectionalCollection = this.GenerateCollectionAssociationPropertyGetter(metadata);

            this.GenerateClosingBrace();

            if (isBiDirectionalCollection)
            {
                this.GenerateAttachMethod(metadata);
                this.GenerateDetachMethod(metadata);
            }
        }
示例#7
0
        private void GenerateAssociationFilterMethod(AssociationMetadata metadata)
        {
            string[] thisKeyProps  = metadata.AssociationAttribute.ThisKeyMembers.ToArray();
            string[] otherKeyProps = metadata.AssociationAttribute.OtherKeyMembers.ToArray();

            this.Write("private bool Filter");

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyName));

            this.Write("(");

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropTypeName));

            this.Write(" entity)\r\n");

            this.GenerateOpeningBrace();

            this.Write("return (");


            for (int i = 0; i < thisKeyProps.Length; i++)
            {
                this.Write("entity.");

                this.Write(this.ToStringHelper.ToStringWithCulture(otherKeyProps[i]));

                this.Write(" == this.");

                this.Write(this.ToStringHelper.ToStringWithCulture(thisKeyProps[i]));


                if (i + 1 < thisKeyProps.Length)
                {
                    this.Write(" && ");
                }
            }

            this.Write(");\r\n");


            this.GenerateClosingBrace();
        }
示例#8
0
        private void GenerateAssociationPropertyDeclaration(AssociationMetadata metadata)
        {
            this.GenerateAttributes(metadata.Attributes);
            string propertyType = String.Empty;

            if (metadata.IsCollection)
            {
                propertyType = metadata.AssociationTypeName;
            }
            else
            {
                propertyType = metadata.PropTypeName;
            }

            this.Write("public ");

            this.Write(this.ToStringHelper.ToStringWithCulture(propertyType));

            this.Write(" ");

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyName));

            this.Write("\r\n");
        }
示例#9
0
        private void GenerateDetachMethod(AssociationMetadata metadata)
        {
            PropertyDescriptor reverseAssociationMember = GetReverseAssociation(metadata.PropertyDescriptor, metadata.AssociationAttribute);
            string             revName          = reverseAssociationMember.Name;
            string             detachMethodName = "Detach" + metadata.PropertyName;

            this.Write("private void ");

            this.Write(this.ToStringHelper.ToStringWithCulture(detachMethodName));

            this.Write("(");

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropTypeName));

            this.Write(" entity)\r\n");


            this.GenerateOpeningBrace();
            if (!metadata.IsCollection)
            {
                this.Write("entity.");

                this.Write(this.ToStringHelper.ToStringWithCulture(revName));

                this.Write(".Remove(this);\r\n");
            }
            else
            {
                this.Write("entity.");

                this.Write(this.ToStringHelper.ToStringWithCulture(revName));

                this.Write(" = null;\r\n");
            }
            this.GenerateClosingBrace();
        }
示例#10
0
        private bool GenerateCollectionAssociationPropertyGetter(AssociationMetadata metadata)
        {
            PropertyDescriptor reverseAssociationMember = GetReverseAssociation(metadata.PropertyDescriptor, metadata.AssociationAttribute);

            bool   isBiDirectionalAssociation = (reverseAssociationMember != null) && this.CanGenerateProperty(reverseAssociationMember);
            string revName = isBiDirectionalAssociation ? reverseAssociationMember.Name : string.Empty;

            bool isBiDirectionalCollection = isBiDirectionalAssociation && metadata.IsCollection;

            string detachMethodName = "Detach" + metadata.PropertyName;
            string attachMethodName = "Attach" + metadata.PropertyName;

            this.Write("get\r\n");


            this.GenerateOpeningBrace();

            this.Write("if(this.");

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

            this.Write(" == null)\r\n");


            this.GenerateOpeningBrace();

            this.Write("this.");

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

            this.Write(" = new ");

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.AssociationTypeName));

            this.Write("(this, \"");

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyName));

            this.Write("\", this.Filter");

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyName));


            if (isBiDirectionalCollection)
            {
                this.Write(", this.");

                this.Write(this.ToStringHelper.ToStringWithCulture(attachMethodName));

                this.Write(", this.");

                this.Write(this.ToStringHelper.ToStringWithCulture(detachMethodName));
            }

            this.Write(");\r\n");


            this.GenerateClosingBrace();

            this.Write("return this.");

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

            this.Write(";\r\n");


            this.GenerateClosingBrace();

            return(isBiDirectionalCollection);
        }
	private bool GenerateCollectionAssociationPropertyGetter(AssociationMetadata metadata)
	{
		PropertyDescriptor reverseAssociationMember = GetReverseAssociation(metadata.PropertyDescriptor, metadata.AssociationAttribute);
		
		bool isBiDirectionalAssociation = (reverseAssociationMember != null) && this.CanGenerateProperty(reverseAssociationMember);
		string revName = isBiDirectionalAssociation ? reverseAssociationMember.Name : string.Empty;

		bool isBiDirectionalCollection = isBiDirectionalAssociation && metadata.IsCollection;
		
		string detachMethodName = "Detach" + metadata.PropertyName;
		string attachMethodName = "Attach" + metadata.PropertyName;

        
        #line default
        #line hidden
        
        #line 242 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("get\r\n");

        
        #line default
        #line hidden
        
        #line 244 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

		this.GenerateOpeningBrace();	

        
        #line default
        #line hidden
        
        #line 246 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("if(this.");

        
        #line default
        #line hidden
        
        #line 247 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

        
        #line default
        #line hidden
        
        #line 247 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(" == null)\r\n");

        
        #line default
        #line hidden
        
        #line 248 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

		this.GenerateOpeningBrace();	

        
        #line default
        #line hidden
        
        #line 250 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("this.");

        
        #line default
        #line hidden
        
        #line 251 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

        
        #line default
        #line hidden
        
        #line 251 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(" = new ");

        
        #line default
        #line hidden
        
        #line 251 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.AssociationTypeName));

        
        #line default
        #line hidden
        
        #line 251 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("(this, \"");

        
        #line default
        #line hidden
        
        #line 251 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyName));

        
        #line default
        #line hidden
        
        #line 251 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("\", this.Filter");

        
        #line default
        #line hidden
        
        #line 251 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyName));

        
        #line default
        #line hidden
        
        #line 251 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

		if(isBiDirectionalCollection)
		{

        
        #line default
        #line hidden
        
        #line 254 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(", this.");

        
        #line default
        #line hidden
        
        #line 254 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(attachMethodName));

        
        #line default
        #line hidden
        
        #line 254 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(", this.");

        
        #line default
        #line hidden
        
        #line 254 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(detachMethodName));

        
        #line default
        #line hidden
        
        #line 254 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
			
		}

        
        #line default
        #line hidden
        
        #line 256 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(");\r\n");

        
        #line default
        #line hidden
        
        #line 257 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

		this.GenerateClosingBrace();

        
        #line default
        #line hidden
        
        #line 259 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("return this.");

        
        #line default
        #line hidden
        
        #line 260 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

        
        #line default
        #line hidden
        
        #line 260 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(";\r\n");

        
        #line default
        #line hidden
        
        #line 261 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

		this.GenerateClosingBrace();
		
		return isBiDirectionalCollection;
	}
	private void GenerateSingletonAssociationPropertySetter(AssociationMetadata metadata)
	{
		if (metadata.IsExternal && !metadata.AssociationAttribute.IsForeignKey)
		{
			return;
		}
		

this.Write("set\r\n");

		this.GenerateOpeningBrace();

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropTypeName));

this.Write(" previous = this.");

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyDescriptor.Name));

this.Write(";\r\nif (previous != value)\r\n");

		this.GenerateOpeningBrace();

this.Write("this.ValidateProperty(\"");

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyDescriptor.Name));

this.Write("\", value);\r\n");


		PropertyDescriptor reverseAssociationMember = GetReverseAssociation(metadata.PropertyDescriptor, metadata.AssociationAttribute);
		
		bool reverseIsSingleton = false;
		bool isBiDirectionalAssociation = (reverseAssociationMember != null) && this.CanGenerateProperty(reverseAssociationMember);
		string revName = isBiDirectionalAssociation ? reverseAssociationMember.Name : string.Empty;
		if(isBiDirectionalAssociation && !metadata.IsExternal)
		{

this.Write("if(previous != null)\r\n");


			this.GenerateOpeningBrace();

this.Write("this.");

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

this.Write(".Entity = null;\r\n");


			reverseIsSingleton = !EntityGenerator.IsCollectionType(reverseAssociationMember.PropertyType);
			if(!reverseIsSingleton)
			{

this.Write("previous.");

this.Write(this.ToStringHelper.ToStringWithCulture(revName));

this.Write(".Remove(this);\r\n");


			}
			else
			{

this.Write("previous.");

this.Write(this.ToStringHelper.ToStringWithCulture(revName));

this.Write(" = null;\r\n");


			}

			this.GenerateClosingBrace();
		}
		
		if(metadata.AssociationAttribute.IsForeignKey)
		{
			string[] thisKeyProps = metadata.AssociationAttribute.ThisKeyMembers.ToArray();
			string[] otherKeyProps = metadata.AssociationAttribute.OtherKeyMembers.ToArray();

this.Write("if(value != null)\r\n");


			this.GenerateOpeningBrace();
			for(int i = 0; i < thisKeyProps.Length; i++)
			{

this.Write("this.");

this.Write(this.ToStringHelper.ToStringWithCulture(thisKeyProps[i]));

this.Write(" = value.");

this.Write(this.ToStringHelper.ToStringWithCulture(otherKeyProps[i]));

this.Write(";\r\n");


			}
			this.GenerateClosingBrace();

this.Write("else\r\n");


			this.GenerateOpeningBrace();
			for(int i = 0; i < thisKeyProps.Length; i++)
			{
				Type foreignKeyType = TypeDescriptor.GetProperties(this.Type).Find(thisKeyProps[i], false).PropertyType;
				string foreignKeyTypeName = CodeGenUtilities.GetTypeName(foreignKeyType);

this.Write("this.");

this.Write(this.ToStringHelper.ToStringWithCulture(thisKeyProps[i]));

this.Write(" = default(");

this.Write(this.ToStringHelper.ToStringWithCulture(foreignKeyTypeName));

this.Write(");\r\n");


			}
			this.GenerateClosingBrace();
			
			if(!metadata.IsExternal)
			{
				this.GenerateSingletonAssociationPropertySetterEntitySetStatement(metadata, isBiDirectionalAssociation, reverseIsSingleton, revName);
			}
		}
		else
		{
			this.GenerateSingletonAssociationPropertySetterEntitySetStatement(metadata, isBiDirectionalAssociation, reverseIsSingleton, revName);
		}
		
		if(!metadata.IsExternal)
		{

this.Write("this.RaisePropertyChanged(\"");

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyDescriptor.Name));

this.Write("\");\r\n");


		}
		this.GenerateClosingBrace();
		this.GenerateClosingBrace();
	}
	private void GenerateSingletonAssociationPropertyGetter(AssociationMetadata metadata)
	{
		string returnType = metadata.FieldName;
		if(!metadata.IsCollection)
		{
			returnType = returnType + ".Entity";
		}

this.Write("get\r\n{\r\n\tif(this.");

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

this.Write(" == null)\r\n\t{\r\n\t\tthis.");

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

this.Write(" = new ");

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.AssociationTypeName));

this.Write("(this, \"");

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyName));

this.Write("\", this.Filter");

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyName));

this.Write(");\r\n\t}\r\n\treturn this.");

this.Write(this.ToStringHelper.ToStringWithCulture(returnType));

this.Write(";\r\n}\r\n");


	}
	private void GenerateAssociationPropertyDeclaration(AssociationMetadata metadata)
	{
		this.GenerateAttributes(metadata.Attributes);
		string propertyType = String.Empty;
		if(metadata.IsCollection)
		{
			propertyType = metadata.AssociationTypeName;
		}
		else
		{
			propertyType = metadata.PropTypeName;
		}

this.Write("public ");

this.Write(this.ToStringHelper.ToStringWithCulture(propertyType));

this.Write(" ");

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyName));

this.Write("\r\n");


	}
	private void GenerateSingletonAssociationPropertySetterEntitySetStatement(AssociationMetadata metadata, bool isBiDirectionalAssociation, bool reverseIsSingleton, string revName)
	{

this.Write("this.");

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

this.Write(".Entity = value;\r\n");


		if(isBiDirectionalAssociation)
		{

this.Write("if(value != null)\r\n");


			this.GenerateOpeningBrace();
			if(!reverseIsSingleton)
			{

this.Write("value.");

this.Write(this.ToStringHelper.ToStringWithCulture(revName));

this.Write(".Add(this);\r\n");


			}
			else
			{

this.Write("value.");

this.Write(this.ToStringHelper.ToStringWithCulture(revName));

this.Write(" = this;\r\n");


			}
			this.GenerateClosingBrace();
			
		}
	}
示例#16
0
        private void GenerateSingletonAssociationPropertySetter(AssociationMetadata metadata)
        {
            if (metadata.IsExternal && !metadata.AssociationAttribute.IsForeignKey)
            {
                return;
            }


            this.Write("set\r\n");

            this.GenerateOpeningBrace();

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropTypeName));

            this.Write(" previous = this.");

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyDescriptor.Name));

            this.Write(";\r\nif (previous != value)\r\n");

            this.GenerateOpeningBrace();

            this.Write("this.ValidateProperty(\"");

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyDescriptor.Name));

            this.Write("\", value);\r\n");


            PropertyDescriptor reverseAssociationMember = GetReverseAssociation(metadata.PropertyDescriptor, metadata.AssociationAttribute);

            bool   reverseIsSingleton         = false;
            bool   isBiDirectionalAssociation = (reverseAssociationMember != null) && this.CanGenerateProperty(reverseAssociationMember);
            string revName = isBiDirectionalAssociation ? reverseAssociationMember.Name : string.Empty;

            if (isBiDirectionalAssociation && !metadata.IsExternal)
            {
                this.Write("if(previous != null)\r\n");


                this.GenerateOpeningBrace();

                this.Write("this.");

                this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

                this.Write(".Entity = null;\r\n");


                reverseIsSingleton = !EntityGenerator.IsCollectionType(reverseAssociationMember.PropertyType);
                if (!reverseIsSingleton)
                {
                    this.Write("previous.");

                    this.Write(this.ToStringHelper.ToStringWithCulture(revName));

                    this.Write(".Remove(this);\r\n");
                }
                else
                {
                    this.Write("previous.");

                    this.Write(this.ToStringHelper.ToStringWithCulture(revName));

                    this.Write(" = null;\r\n");
                }

                this.GenerateClosingBrace();
            }

            if (metadata.AssociationAttribute.IsForeignKey)
            {
                string[] thisKeyProps  = metadata.AssociationAttribute.ThisKeyMembers.ToArray();
                string[] otherKeyProps = metadata.AssociationAttribute.OtherKeyMembers.ToArray();

                this.Write("if(value != null)\r\n");


                this.GenerateOpeningBrace();
                for (int i = 0; i < thisKeyProps.Length; i++)
                {
                    this.Write("this.");

                    this.Write(this.ToStringHelper.ToStringWithCulture(thisKeyProps[i]));

                    this.Write(" = value.");

                    this.Write(this.ToStringHelper.ToStringWithCulture(otherKeyProps[i]));

                    this.Write(";\r\n");
                }
                this.GenerateClosingBrace();

                this.Write("else\r\n");


                this.GenerateOpeningBrace();
                for (int i = 0; i < thisKeyProps.Length; i++)
                {
                    Type   foreignKeyType     = TypeDescriptor.GetProperties(this.Type).Find(thisKeyProps[i], false).PropertyType;
                    string foreignKeyTypeName = CodeGenUtilities.GetTypeName(foreignKeyType);

                    this.Write("this.");

                    this.Write(this.ToStringHelper.ToStringWithCulture(thisKeyProps[i]));

                    this.Write(" = default(");

                    this.Write(this.ToStringHelper.ToStringWithCulture(foreignKeyTypeName));

                    this.Write(");\r\n");
                }
                this.GenerateClosingBrace();

                if (!metadata.IsExternal)
                {
                    this.GenerateSingletonAssociationPropertySetterEntitySetStatement(metadata, isBiDirectionalAssociation, reverseIsSingleton, revName);
                }
            }
            else
            {
                this.GenerateSingletonAssociationPropertySetterEntitySetStatement(metadata, isBiDirectionalAssociation, reverseIsSingleton, revName);
            }

            if (!metadata.IsExternal)
            {
                this.Write("this.RaisePropertyChanged(\"");

                this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyDescriptor.Name));

                this.Write("\");\r\n");
            }
            this.GenerateClosingBrace();
            this.GenerateClosingBrace();
        }
	private void GenerateDetachMethod(AssociationMetadata metadata)
	{
		PropertyDescriptor reverseAssociationMember = GetReverseAssociation(metadata.PropertyDescriptor, metadata.AssociationAttribute);
		string revName = reverseAssociationMember.Name;
		string detachMethodName = "Detach" + metadata.PropertyName;

this.Write("private void ");

this.Write(this.ToStringHelper.ToStringWithCulture(detachMethodName));

this.Write("(");

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropTypeName));

this.Write(" entity)\r\n");


		this.GenerateOpeningBrace();
		if(!metadata.IsCollection)
		{

this.Write("entity.");

this.Write(this.ToStringHelper.ToStringWithCulture(revName));

this.Write(".Remove(this);\r\n");


		}
		else
		{

this.Write("entity.");

this.Write(this.ToStringHelper.ToStringWithCulture(revName));

this.Write(" = null;\r\n");


		}
		this.GenerateClosingBrace();
	}
	private bool GenerateCollectionAssociationPropertyGetter(AssociationMetadata metadata)
	{
		PropertyDescriptor reverseAssociationMember = GetReverseAssociation(metadata.PropertyDescriptor, metadata.AssociationAttribute);
		
		bool isBiDirectionalAssociation = (reverseAssociationMember != null) && this.CanGenerateProperty(reverseAssociationMember);
		string revName = isBiDirectionalAssociation ? reverseAssociationMember.Name : string.Empty;

		bool isBiDirectionalCollection = isBiDirectionalAssociation && metadata.IsCollection;
		
		string detachMethodName = "Detach" + metadata.PropertyName;
		string attachMethodName = "Attach" + metadata.PropertyName;

this.Write("get\r\n");


		this.GenerateOpeningBrace();

this.Write("if(this.");

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

this.Write(" == null)\r\n");


		this.GenerateOpeningBrace();

this.Write("this.");

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

this.Write(" = new ");

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.AssociationTypeName));

this.Write("(this, \"");

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyName));

this.Write("\", this.Filter");

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyName));


		if(isBiDirectionalCollection)
		{

this.Write(", this.");

this.Write(this.ToStringHelper.ToStringWithCulture(attachMethodName));

this.Write(", this.");

this.Write(this.ToStringHelper.ToStringWithCulture(detachMethodName));


		}

this.Write(");\r\n");


		this.GenerateClosingBrace();

this.Write("return this.");

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

this.Write(";\r\n");


		this.GenerateClosingBrace();
		
		return isBiDirectionalCollection;
	}
	private void GenerateCollectionAssociationProperty(AssociationMetadata metadata)
	{
		this.GenerateAssociationPropertyDeclaration(metadata);
		this.GenerateOpeningBrace();
		bool isBiDirectionalCollection = this.GenerateCollectionAssociationPropertyGetter(metadata);
		this.GenerateClosingBrace();
		
		if(isBiDirectionalCollection)
		{
			this.GenerateAttachMethod(metadata);
			this.GenerateDetachMethod(metadata);
		}
	}
	private void GenerateAssociationFilterMethod(AssociationMetadata metadata)
	{		
		string[] thisKeyProps = metadata.AssociationAttribute.ThisKeyMembers.ToArray();
		string[] otherKeyProps = metadata.AssociationAttribute.OtherKeyMembers.ToArray();

this.Write("private bool Filter");

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyName));

this.Write("(");

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropTypeName));

this.Write(" entity)\r\n");

 	this.GenerateOpeningBrace(); 

this.Write("return (");

  
		for(int i = 0; i < thisKeyProps.Length; i++)
		{

this.Write("entity.");

this.Write(this.ToStringHelper.ToStringWithCulture(otherKeyProps[i]));

this.Write(" == this.");

this.Write(this.ToStringHelper.ToStringWithCulture(thisKeyProps[i]));


			if(i + 1 < thisKeyProps.Length)
			{
				
this.Write(" && ");


			}
		}

this.Write(");\r\n");


		this.GenerateClosingBrace();
	}
	private void GenerateAssociationFilterMethod(AssociationMetadata metadata)
	{		
		string[] thisKeyProps = metadata.AssociationAttribute.ThisKeyMembers.ToArray();
        string[] otherKeyProps = metadata.AssociationAttribute.OtherKeyMembers.ToArray();

        
        #line default
        #line hidden
        
        #line 191 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("private bool Filter");

        
        #line default
        #line hidden
        
        #line 192 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyName));

        
        #line default
        #line hidden
        
        #line 192 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("(");

        
        #line default
        #line hidden
        
        #line 192 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropTypeName));

        
        #line default
        #line hidden
        
        #line 192 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(" entity)\r\n");

        
        #line default
        #line hidden
        
        #line 193 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
 	this.GenerateOpeningBrace(); 

        
        #line default
        #line hidden
        
        #line 194 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("return (");

        
        #line default
        #line hidden
        
        #line 195 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
  
		for(int i = 0; i < thisKeyProps.Length; i++)
		{

        
        #line default
        #line hidden
        
        #line 198 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("entity.");

        
        #line default
        #line hidden
        
        #line 198 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(otherKeyProps[i]));

        
        #line default
        #line hidden
        
        #line 198 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(" == this.");

        
        #line default
        #line hidden
        
        #line 198 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(thisKeyProps[i]));

        
        #line default
        #line hidden
        
        #line 198 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

			if(i + 1 < thisKeyProps.Length)
			{
				
        
        #line default
        #line hidden
        
        #line 201 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(" && ");

        
        #line default
        #line hidden
        
        #line 201 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

			}
		}

        
        #line default
        #line hidden
        
        #line 204 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(");\r\n");

        
        #line default
        #line hidden
        
        #line 205 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

		this.GenerateClosingBrace();
	}
	private void GenerateSingletonAssociationPropertySetterEntitySetStatement(AssociationMetadata metadata, bool isBiDirectionalAssociation, bool reverseIsSingleton, string revName)
	{

        
        #line default
        #line hidden
        
        #line 161 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("this.");

        
        #line default
        #line hidden
        
        #line 162 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

        
        #line default
        #line hidden
        
        #line 162 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(".Entity = value;\r\n");

        
        #line default
        #line hidden
        
        #line 163 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

		if(isBiDirectionalAssociation)
		{

        
        #line default
        #line hidden
        
        #line 166 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("if(value != null)\r\n");

        
        #line default
        #line hidden
        
        #line 168 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

			this.GenerateOpeningBrace();
			if(!reverseIsSingleton)
			{

        
        #line default
        #line hidden
        
        #line 172 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("value.");

        
        #line default
        #line hidden
        
        #line 173 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(revName));

        
        #line default
        #line hidden
        
        #line 173 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(".Add(this);\r\n");

        
        #line default
        #line hidden
        
        #line 174 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

			}
			else
			{

        
        #line default
        #line hidden
        
        #line 178 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("value.");

        
        #line default
        #line hidden
        
        #line 179 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(revName));

        
        #line default
        #line hidden
        
        #line 179 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(" = this;\r\n");

        
        #line default
        #line hidden
        
        #line 180 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

			}
			this.GenerateClosingBrace();
			
		}
	}
	private void GenerateSingletonAssociation(PropertyDescriptor pd)
	{
		AssociationMetadata metadata = new AssociationMetadata(pd);
		this.GenerateAssociationField(metadata);
		this.GenerateSingletonAssociationProperty(metadata);
		this.GenerateAssociationFilterMethod(metadata);
	}
	private void GenerateDetachMethod(AssociationMetadata metadata)
	{
		PropertyDescriptor reverseAssociationMember = GetReverseAssociation(metadata.PropertyDescriptor, metadata.AssociationAttribute);		
		string revName = reverseAssociationMember.Name;
		string detachMethodName = "Detach" + metadata.PropertyName;

        
        #line default
        #line hidden
        
        #line 296 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("private void ");

        
        #line default
        #line hidden
        
        #line 297 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(detachMethodName));

        
        #line default
        #line hidden
        
        #line 297 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("(");

        
        #line default
        #line hidden
        
        #line 297 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropTypeName));

        
        #line default
        #line hidden
        
        #line 297 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(" entity)\r\n");

        
        #line default
        #line hidden
        
        #line 298 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

		this.GenerateOpeningBrace();		
		if(!metadata.IsCollection)
		{

        
        #line default
        #line hidden
        
        #line 302 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("entity.");

        
        #line default
        #line hidden
        
        #line 303 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(revName));

        
        #line default
        #line hidden
        
        #line 303 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(".Remove(this);\r\n");

        
        #line default
        #line hidden
        
        #line 304 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

		}
		else
		{

        
        #line default
        #line hidden
        
        #line 308 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("entity.");

        
        #line default
        #line hidden
        
        #line 309 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(revName));

        
        #line default
        #line hidden
        
        #line 309 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(" = null;\r\n");

        
        #line default
        #line hidden
        
        #line 310 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

		}		
		this.GenerateClosingBrace();	
	}
	private void GenerateSingletonAssociationPropertyGetter(AssociationMetadata metadata)
	{
		string returnType = metadata.FieldName;
		if(!metadata.IsCollection)
		{
			returnType = returnType + ".Entity";
		}

        
        #line default
        #line hidden
        
        #line 50 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("get\r\n{\r\n\tif(this.");

        
        #line default
        #line hidden
        
        #line 53 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

        
        #line default
        #line hidden
        
        #line 53 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(" == null)\r\n\t{\r\n\t\tthis.");

        
        #line default
        #line hidden
        
        #line 55 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

        
        #line default
        #line hidden
        
        #line 55 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(" = new ");

        
        #line default
        #line hidden
        
        #line 55 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.AssociationTypeName));

        
        #line default
        #line hidden
        
        #line 55 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("(this, \"");

        
        #line default
        #line hidden
        
        #line 55 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyName));

        
        #line default
        #line hidden
        
        #line 55 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("\", this.Filter");

        
        #line default
        #line hidden
        
        #line 55 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyName));

        
        #line default
        #line hidden
        
        #line 55 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(");\r\n\t}\r\n\treturn this.");

        
        #line default
        #line hidden
        
        #line 57 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(returnType));

        
        #line default
        #line hidden
        
        #line 57 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(";\r\n}\r\n");

        
        #line default
        #line hidden
        
        #line 59 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

	}
	private void GenerateAssociationPropertyDeclaration(AssociationMetadata metadata)
	{
		this.GenerateAttributes(metadata.Attributes);
		string propertyType = String.Empty;
		if(metadata.IsCollection)
		{
			propertyType = metadata.AssociationTypeName;			
		}
		else
		{
			propertyType = metadata.PropTypeName;
		}

        
        #line default
        #line hidden
        
        #line 38 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("public ");

        
        #line default
        #line hidden
        
        #line 39 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(propertyType));

        
        #line default
        #line hidden
        
        #line 39 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(" ");

        
        #line default
        #line hidden
        
        #line 39 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyName));

        
        #line default
        #line hidden
        
        #line 39 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("\r\n");

        
        #line default
        #line hidden
        
        #line 40 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

	}
	private void GenerateAssociationField(AssociationMetadata metadata)
	{

this.Write("private ");

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.AssociationTypeName));

this.Write(" ");

this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

this.Write(";\r\n");


	}
	private void GenerateSingletonAssociationPropertySetter(AssociationMetadata metadata)
	{
		if (metadata.IsExternal && !metadata.AssociationAttribute.IsForeignKey)
        {
			return;
		}
		

        
        #line default
        #line hidden
        
        #line 69 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("set\r\n");

        
        #line default
        #line hidden
        
        #line 71 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
  	this.GenerateOpeningBrace();

        
        #line default
        #line hidden
        
        #line 73 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropTypeName));

        
        #line default
        #line hidden
        
        #line 73 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(" previous = this.");

        
        #line default
        #line hidden
        
        #line 73 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyDescriptor.Name));

        
        #line default
        #line hidden
        
        #line 73 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(";\r\nif (previous != value)\r\n");

        
        #line default
        #line hidden
        
        #line 75 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
  	this.GenerateOpeningBrace();

        
        #line default
        #line hidden
        
        #line 76 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("this.ValidateProperty(\"");

        
        #line default
        #line hidden
        
        #line 77 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyDescriptor.Name));

        
        #line default
        #line hidden
        
        #line 77 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("\", value);\r\n");

        
        #line default
        #line hidden
        
        #line 78 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

		PropertyDescriptor reverseAssociationMember = GetReverseAssociation(metadata.PropertyDescriptor, metadata.AssociationAttribute);
		
		bool reverseIsSingleton = false;
		bool isBiDirectionalAssociation = (reverseAssociationMember != null) && this.CanGenerateProperty(reverseAssociationMember);	
		string revName = isBiDirectionalAssociation ? reverseAssociationMember.Name : string.Empty;
		if(isBiDirectionalAssociation && !metadata.IsExternal)
		{

        
        #line default
        #line hidden
        
        #line 86 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("if(previous != null)\r\n");

        
        #line default
        #line hidden
        
        #line 88 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

			this.GenerateOpeningBrace();

        
        #line default
        #line hidden
        
        #line 90 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("this.");

        
        #line default
        #line hidden
        
        #line 91 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

        
        #line default
        #line hidden
        
        #line 91 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(".Entity = null;\r\n");

        
        #line default
        #line hidden
        
        #line 92 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

			reverseIsSingleton = !EntityGenerator.IsCollectionType(reverseAssociationMember.PropertyType);
			if(!reverseIsSingleton)
			{

        
        #line default
        #line hidden
        
        #line 96 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("previous.");

        
        #line default
        #line hidden
        
        #line 97 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(revName));

        
        #line default
        #line hidden
        
        #line 97 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(".Remove(this);\r\n");

        
        #line default
        #line hidden
        
        #line 98 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

			}
			else
			{

        
        #line default
        #line hidden
        
        #line 102 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("previous.");

        
        #line default
        #line hidden
        
        #line 103 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(revName));

        
        #line default
        #line hidden
        
        #line 103 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(" = null;\r\n");

        
        #line default
        #line hidden
        
        #line 104 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

			}
				
			this.GenerateClosingBrace();
		}
		
		if(metadata.AssociationAttribute.IsForeignKey)
		{
			string[] thisKeyProps = metadata.AssociationAttribute.ThisKeyMembers.ToArray();
    	    string[] otherKeyProps = metadata.AssociationAttribute.OtherKeyMembers.ToArray();

        
        #line default
        #line hidden
        
        #line 114 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("if(value != null)\r\n");

        
        #line default
        #line hidden
        
        #line 116 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

			this.GenerateOpeningBrace();
			for(int i = 0; i < thisKeyProps.Length; i++)
			{

        
        #line default
        #line hidden
        
        #line 120 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("this.");

        
        #line default
        #line hidden
        
        #line 121 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(thisKeyProps[i]));

        
        #line default
        #line hidden
        
        #line 121 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(" = value.");

        
        #line default
        #line hidden
        
        #line 121 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(otherKeyProps[i]));

        
        #line default
        #line hidden
        
        #line 121 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(";\r\n");

        
        #line default
        #line hidden
        
        #line 122 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

			}
			this.GenerateClosingBrace();

        
        #line default
        #line hidden
        
        #line 125 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("else\r\n");

        
        #line default
        #line hidden
        
        #line 127 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

			this.GenerateOpeningBrace();
			for(int i = 0; i < thisKeyProps.Length; i++)
			{
				Type foreignKeyType = TypeDescriptor.GetProperties(this.Type).Find(thisKeyProps[i], false).PropertyType;
				string foreignKeyTypeName = CodeGenUtilities.GetTypeName(foreignKeyType);

        
        #line default
        #line hidden
        
        #line 133 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("this.");

        
        #line default
        #line hidden
        
        #line 134 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(thisKeyProps[i]));

        
        #line default
        #line hidden
        
        #line 134 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(" = default(");

        
        #line default
        #line hidden
        
        #line 134 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(foreignKeyTypeName));

        
        #line default
        #line hidden
        
        #line 134 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(");\r\n");

        
        #line default
        #line hidden
        
        #line 135 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

			}			
			this.GenerateClosingBrace();
			
			if(!metadata.IsExternal)
			{
				this.GenerateSingletonAssociationPropertySetterEntitySetStatement(metadata, isBiDirectionalAssociation, reverseIsSingleton, revName);
			}
		}
		else
		{
			this.GenerateSingletonAssociationPropertySetterEntitySetStatement(metadata, isBiDirectionalAssociation, reverseIsSingleton, revName);			
		}
		
		if(!metadata.IsExternal)
		{

        
        #line default
        #line hidden
        
        #line 151 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("this.RaisePropertyChanged(\"");

        
        #line default
        #line hidden
        
        #line 152 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyDescriptor.Name));

        
        #line default
        #line hidden
        
        #line 152 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("\");\r\n");

        
        #line default
        #line hidden
        
        #line 153 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

		}
		this.GenerateClosingBrace();
		this.GenerateClosingBrace();
	}
	private void GenerateSingletonAssociationProperty(AssociationMetadata metadata)
	{
		this.GenerateAssociationPropertyDeclaration(metadata);
		this.GenerateOpeningBrace();
		this.GenerateSingletonAssociationPropertyGetter(metadata);
		this.GenerateSingletonAssociationPropertySetter(metadata);
		this.GenerateClosingBrace();
	}
	private void GenerateAssociationField(AssociationMetadata metadata)
	{		

        
        #line default
        #line hidden
        
        #line 12 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write("private ");

        
        #line default
        #line hidden
        
        #line 13 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.AssociationTypeName));

        
        #line default
        #line hidden
        
        #line 13 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(" ");

        
        #line default
        #line hidden
        
        #line 13 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

        
        #line default
        #line hidden
        
        #line 13 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"
this.Write(";\r\n");

        
        #line default
        #line hidden
        
        #line 14 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AssociationGenerator.ttinclude"

	}