Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleForeignKeyIndexProperty"/> class.
        /// </summary>
        /// <param name="foreignKeyElement">The column schema.</param>
        public SimpleForeignKeyIndexProperty(ForeignKeyElement foreignKeyElement)
        {
            // Initialize the object.
            this.foreignKeyElement = foreignKeyElement ?? throw new ArgumentNullException(nameof(foreignKeyElement));
            this.Name = this.foreignKeyElement.Name;

            //        /// <summary>
            //        /// Gets the CountryBuyerCountryIdKey foreign index.
            //        /// </summary>
            //        public SimpleForeignKeyIndex<Buyer, Country> CountryBuyerCountryIdKey
            //        {
            //            <Get>
            //        }
            this.Syntax = SyntaxFactory.PropertyDeclaration(
                SyntaxFactory.GenericName(
                    SyntaxFactory.Identifier("SimpleForeignKeyIndex"))
                .WithTypeArgumentList(
                    SyntaxFactory.TypeArgumentList(
                        SyntaxFactory.SeparatedList <TypeSyntax>(
                            new SyntaxNodeOrToken[]
            {
                SyntaxFactory.IdentifierName(this.foreignKeyElement.Table.Name),
                SyntaxFactory.Token(SyntaxKind.CommaToken),
                SyntaxFactory.IdentifierName(this.foreignKeyElement.UniqueKey.Table.Name),
            }))),
                SyntaxFactory.Identifier(this.foreignKeyElement.Name))
                          .WithAccessorList(this.AccessorList)
                          .WithModifiers(SimpleForeignKeyIndexProperty.Modifiers)
                          .WithLeadingTrivia(this.DocumentationComment);
        }
Exemple #2
0
        /// <summary>
        /// Creates the element that describes a foreign constraint.
        /// </summary>
        /// <param name="foreignKeyElement">A description of a foreign constraint.</param>
        /// <returns>An element that can be used in an XML Schema document to describe a foreign constraint.</returns>
        private static XElement CreateForeignKey(ForeignKeyElement foreignKeyElement)
        {
            //    <xs:keyref name="FK_Entity_AccessControl" refer="EntityKey" msprop:rel_Generator_UserRelationName="FK_Entity_AccessControl"
            //        msprop:rel_Generator_RelationVarName="relationFK_Entity_AccessControl" msprop:rel_Generator_UserChildTable="AccessControl"
            //        msprop:rel_Generator_UserParentTable="Entity" msprop:rel_Generator_ParentPropName="EntityRow"
            //        msprop:rel_Generator_ChildPropName="GetAccessControlRows">
            //      <xs:selector xpath=".//mstns:AccessControl" />
            //      <xs:field xpath="mstns:EntityId" />
            //    </xs:keyref>
            XElement foreignElement = new XElement(
                ScrubXsdCommand.xs + "keyref",
                new XAttribute("name", foreignKeyElement.Name),
                new XAttribute("refer", foreignKeyElement.UniqueKey.Name));

            foreignElement.Add(
                new XElement(
                    ScrubXsdCommand.xs + "selector",
                    new XAttribute("xpath", string.Format(".//mstns:{0}", foreignKeyElement.Table.Name))));

            foreach (ColumnReferenceElement columnReferenceElement in foreignKeyElement.Columns.OrderBy(c => c.Name))
            {
                ColumnElement columnElement = columnReferenceElement.Column;
                foreignElement.Add(
                    new XElement(
                        ScrubXsdCommand.xs + "field",
                        new XAttribute("xpath", string.Format("mstns:{0}", columnElement.Name))));
            }

            // This describes a foreign constraint on a table.
            return(foreignElement);
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleForeignKeyIndexField"/> class.
        /// </summary>
        /// <param name="foreignKeyElement">The description of the unique key.</param>
        public SimpleForeignKeyIndexField(ForeignKeyElement foreignKeyElement)
        {
            // Initialize the object.
            this.foreignKeyElement = foreignKeyElement ?? throw new ArgumentNullException(nameof(foreignKeyElement));
            this.Name = this.foreignKeyElement.Name;

            //        /// <summary>
            //        /// The CountryBuyerCountryIdKey foreign index.
            //        /// </summary>
            //        private SimpleForeignKeyIndex<Buyer, Country> countryBuyerCountryIdKey;
            this.Syntax = SyntaxFactory.FieldDeclaration(
                SyntaxFactory.VariableDeclaration(
                    SyntaxFactory.GenericName(
                        SyntaxFactory.Identifier("SimpleForeignKeyIndex"))
                    .WithTypeArgumentList(
                        SyntaxFactory.TypeArgumentList(
                            SyntaxFactory.SeparatedList <TypeSyntax>(
                                new SyntaxNodeOrToken[]
            {
                SyntaxFactory.IdentifierName(this.foreignKeyElement.Table.Name),
                SyntaxFactory.Token(SyntaxKind.CommaToken),
                SyntaxFactory.IdentifierName(this.foreignKeyElement.UniqueKey.Table.Name),
            }))))
                .WithVariables(
                    SyntaxFactory.SingletonSeparatedList <VariableDeclaratorSyntax>(
                        SyntaxFactory.VariableDeclarator(
                            SyntaxFactory.Identifier(this.foreignKeyElement.Name.ToVariableName())))))
                          .WithModifiers(SimpleForeignKeyIndexField.Modifiers)
                          .WithLeadingTrivia(this.DocumentationComment);
        }
Exemple #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GetChildrenFunctionField"/> class.
        /// </summary>
        /// <param name="foreignKeyElement">A description of a foreign key.</param>
        public GetChildrenFunctionField(ForeignKeyElement foreignKeyElement)
        {
            // Initialize the object.
            this.foreignKeyElement = foreignKeyElement ?? throw new ArgumentNullException(nameof(foreignKeyElement));
            this.Name = $"get{this.foreignKeyElement.UniqueChildName}";

            //        /// <summary>
            //        /// Function to get child Buyers.
            //        /// </summary>
            //        private Func<IEnumerable<Buyer>> getBuyers;
            this.Syntax = SyntaxFactory.FieldDeclaration(
                SyntaxFactory.VariableDeclaration(
                    SyntaxFactory.GenericName(
                        SyntaxFactory.Identifier("Func"))
                    .WithTypeArgumentList(
                        SyntaxFactory.TypeArgumentList(
                            SyntaxFactory.SingletonSeparatedList <TypeSyntax>(
                                SyntaxFactory.GenericName(
                                    SyntaxFactory.Identifier("IEnumerable"))
                                .WithTypeArgumentList(
                                    SyntaxFactory.TypeArgumentList(
                                        SyntaxFactory.SingletonSeparatedList <TypeSyntax>(
                                            SyntaxFactory.IdentifierName(this.foreignKeyElement.Table.Name))))))))
                .WithVariables(
                    SyntaxFactory.SingletonSeparatedList <VariableDeclaratorSyntax>(
                        SyntaxFactory.VariableDeclarator(
                            SyntaxFactory.Identifier(this.Name)))))
                          .WithModifiers(GetChildrenFunctionField.Modifiers)
                          .WithLeadingTrivia(this.DocumentationComment);
        }
Exemple #5
0
        /// <summary>
        /// Creates an argument that creates a lambda expression for extracting the key from a class.
        /// </summary>
        /// <param name="foreignKeyElement">The unique key element.</param>
        /// <returns>An argument that extracts a key from an object.</returns>
        public static ExpressionSyntax GetForeignKey(ForeignKeyElement foreignKeyElement)
        {
            // Validate the parameter
            if (foreignKeyElement == null)
            {
                throw new ArgumentNullException(nameof(foreignKeyElement));
            }

            // Used as a variable when constructing the lambda expression.
            string abbreviation = foreignKeyElement.Table.Name[0].ToString(CultureInfo.InvariantCulture).ToLowerInvariant();

            // This will create an expression for extracting the key from record.
            CSharpSyntaxNode syntaxNode = null;

            if (foreignKeyElement.Columns.Count == 1)
            {
                // A simple key can be used like a value type.
                syntaxNode = SyntaxFactory.MemberAccessExpression(
                    SyntaxKind.SimpleMemberAccessExpression,
                    SyntaxFactory.IdentifierName(abbreviation),
                    SyntaxFactory.IdentifierName(foreignKeyElement.Columns[0].Column.Name));
            }
            else
            {
                // A Compound key must be constructed from an anomymous type.
                List <SyntaxNodeOrToken> keyElements = new List <SyntaxNodeOrToken>();
                foreach (ColumnReferenceElement columnReferenceElement in foreignKeyElement.Columns)
                {
                    if (keyElements.Count != 0)
                    {
                        keyElements.Add(SyntaxFactory.Token(SyntaxKind.CommaToken));
                    }

                    keyElements.Add(
                        SyntaxFactory.AnonymousObjectMemberDeclarator(
                            SyntaxFactory.MemberAccessExpression(
                                SyntaxKind.SimpleMemberAccessExpression,
                                SyntaxFactory.IdentifierName(abbreviation),
                                SyntaxFactory.IdentifierName(columnReferenceElement.Column.Name))));
                }

                // b => b.BuyerId or b => new { b.BuyerId, b.ExternalId0 }
                syntaxNode = SyntaxFactory.AnonymousObjectCreationExpression(
                    SyntaxFactory.SeparatedList <AnonymousObjectMemberDeclaratorSyntax>(keyElements.ToArray()));
            }

            //            this.BuyerKey = new SimpleForeignKeyIndex<Buyer>("BuyerKey").HasIndex(b => b.BuyerId);
            return(SyntaxFactory.SimpleLambdaExpression(SyntaxFactory.Parameter(SyntaxFactory.Identifier(abbreviation)), syntaxNode));
        }
Exemple #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ParentProperty"/> class.
        /// </summary>
        /// <param name="foreignKeyElement">The column schema.</param>
        public ParentProperty(ForeignKeyElement foreignKeyElement)
        {
            // Initialize the object.
            this.foreignKeyElement = foreignKeyElement ?? throw new ArgumentNullException(nameof(foreignKeyElement));
            this.Name = this.foreignKeyElement.UniqueParentName;

            //        /// <summary>
            //        /// Gets the parent <see cref="Country"/> record.
            //        /// </summary>
            //        public Country Country < Get >
            this.Syntax = SyntaxFactory.PropertyDeclaration(
                SyntaxFactory.IdentifierName(this.foreignKeyElement.UniqueKey.Table.Name),
                SyntaxFactory.Identifier(this.Name))
                          .WithAccessorList(this.AccessorList)
                          .WithModifiers(ParentProperty.Modifiers)
                          .WithAttributeLists(ParentProperty.Attributes)
                          .WithLeadingTrivia(this.DocumentationComment);
        }
Exemple #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultChildrenField"/> class.
        /// </summary>
        /// <param name="foreignKeyElement">A description of a foreign key.</param>
        public DefaultChildrenField(ForeignKeyElement foreignKeyElement)
        {
            // Initialize the object.
            this.foreignKeyElement = foreignKeyElement ?? throw new ArgumentNullException(nameof(foreignKeyElement));
            this.Name = $"Default{this.foreignKeyElement.UniqueChildName}";

            //        /// <summary>
            //        /// Default Buyers.
            //        /// </summary>
            //        private static readonly List<Buyer> defaultBuyers = new List<Buyer>();
            this.Syntax = SyntaxFactory.FieldDeclaration(
                SyntaxFactory.VariableDeclaration(
                    SyntaxFactory.GenericName(
                        SyntaxFactory.Identifier("List"))
                    .WithTypeArgumentList(
                        SyntaxFactory.TypeArgumentList(
                            SyntaxFactory.SingletonSeparatedList <TypeSyntax>(
                                SyntaxFactory.IdentifierName(this.foreignKeyElement.Table.Name)))))
                .WithVariables(this.Variables))
                          .WithModifiers(DefaultChildrenField.Modifiers)
                          .WithLeadingTrivia(this.DocumentationComment);
        }
Exemple #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DictionaryField"/> class.
        /// </summary>
        /// <param name="foreignKeyElement">The table schema.</param>
        public DictionaryField(ForeignKeyElement foreignKeyElement)
        {
            // Initialize the object.
            this.foreignKeyElement = foreignKeyElement;

            // This is the name of the field.
            this.Name = "dictionary";

            //        /// <summary>
            //        /// The dictionary containing the index.
            //        /// </summary>
            //        private Dictionary<Guid, ProvinceRow> dictionary = new Dictionary<Guid, ProvinceRow>();
            this.Syntax = SyntaxFactory.FieldDeclaration(
                SyntaxFactory.VariableDeclaration(this.Type)
                .WithVariables(
                    SyntaxFactory.SingletonSeparatedList <VariableDeclaratorSyntax>(
                        SyntaxFactory.VariableDeclarator(
                            SyntaxFactory.Identifier(this.Name))
                        .WithInitializer(this.Initializer))))
                          .WithModifiers(DictionaryField.Modifiers)
                          .WithLeadingTrivia(DictionaryField.DocumentationComment);
        }
Exemple #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChildrenProperty"/> class.
        /// </summary>
        /// <param name="foreignKeyElement">The column schema.</param>
        public ChildrenProperty(ForeignKeyElement foreignKeyElement)
        {
            // Initialize the object.
            this.foreignKeyElement = foreignKeyElement ?? throw new ArgumentNullException(nameof(foreignKeyElement));
            this.Name = this.foreignKeyElement.UniqueChildName;

            //        /// <summary>
            //        /// Gets the child <see cref="Buyer"/> records.
            //        /// </summary>
            //        public IEnumerable<Buyer> Buyers < Get >
            this.Syntax = SyntaxFactory.PropertyDeclaration(
                SyntaxFactory.GenericName(
                    SyntaxFactory.Identifier("IEnumerable"))
                .WithTypeArgumentList(
                    SyntaxFactory.TypeArgumentList(
                        SyntaxFactory.SingletonSeparatedList <TypeSyntax>(
                            SyntaxFactory.IdentifierName(this.foreignKeyElement.Table.Name)))),
                SyntaxFactory.Identifier(this.Name))
                          .WithAccessorList(this.AccessorList)
                          .WithModifiers(ChildrenProperty.Modifiers)
                          .WithAttributeLists(ChildrenProperty.Attributes)
                          .WithLeadingTrivia(this.DocumentationComment);
        }