protected override PropertyDeclaration CreateForeignKeyReference(ClassDeclaration classDeclaration, ForeignKeyColumnSchema foreignKey) { if (foreignKey.Table.PrimaryKey == null) return null; string propertyName = this.NameProvider.GetListPropertyName(foreignKey); string fieldName = this.NameProvider.GetListFieldName(foreignKey); string typeParam = this.NameProvider.GetClassName(foreignKey.Table); CodeDomTypeReference genericList = new CodeDomTypeReference("System.Collections.Generic.List").AddTypeParameters(typeParam); //create the field classDeclaration.Members.Add(new CodeMemberField(genericList.ToCodeDom(), fieldName)); //create the prop var prop = new CodeMemberProperty(); prop.Name = propertyName; prop.Type = genericList.ToCodeDom(); prop.Attributes = MemberAttributes.Final | MemberAttributes.Public; prop.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), fieldName))); prop.SetStatements.Add( new CodeConditionStatement( new CodeBinaryOperatorExpression( new CodeSnippetExpression("value"), CodeBinaryOperatorType.IdentityInequality, new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), fieldName)), new CodeSnippetStatement(String.Format("{1}((EightyProofSolutions.BlogEngine.Core.Models.ITrackPropertyChanges)this).OnPropertyChanged(\"{0}\", this.{2}, value);", propertyName, new String('\t', 5), fieldName)), new CodeAssignStatement( new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), fieldName), new CodeSnippetExpression("value")))); classDeclaration.Members.Add(prop); return null; }