public A_16_ControlForeignKeyCombinedKeyTest()
        {
            _attachmentRecordDef = new AddmlRecordDefinitionBuilder()
                                   .WithAddmlFlatFileDefinition(new AddmlFlatFileDefinitionBuilder().Build())
                                   .Build();

            _messageIdPrimaryKeyFieldDef = new AddmlFieldDefinitionBuilder()
                                           .WithRecordDefinition(_attachmentRecordDef)
                                           .WithName("MessageId")
                                           .IsPartOfPrimaryKey(true)
                                           .Build();
            _attachmentNumberPrimaryKeyFieldDef = new AddmlFieldDefinitionBuilder()
                                                  .WithRecordDefinition(_attachmentRecordDef)
                                                  .WithName("AttachmentNumber")
                                                  .IsPartOfPrimaryKey(true)
                                                  .Build();

            _documentRecordDef = new AddmlRecordDefinitionBuilder()
                                 .WithAddmlFlatFileDefinition(new AddmlFlatFileDefinitionBuilder().Build())
                                 .Build();
            _documentPrimaryKeyFieldDef = new AddmlFieldDefinitionBuilder()
                                          .WithRecordDefinition(_documentRecordDef)
                                          .WithName("DocumentId")
                                          .IsPartOfPrimaryKey(true)
                                          .Build();

            AddmlForeignKey addmlForeignKeyAttachment = new AddmlForeignKey("fk1-attachment");
            AddmlForeignKey addmlForeignKeyDocument   = new AddmlForeignKey("fk2-document");

            _recordWithBothCombinedAndSingleForeignKeyDef = new AddmlRecordDefinitionBuilder()
                                                            .WithAddmlFlatFileDefinition(new AddmlFlatFileDefinitionBuilder().Build())
                                                            .WithRecordProcess(A_16_ControlForeignKey.Name)
                                                            .WithForeignKey(addmlForeignKeyAttachment)
                                                            .WithForeignKey(addmlForeignKeyDocument)
                                                            .Build();
            _primaryKeyFieldDef = new AddmlFieldDefinitionBuilder()
                                  .WithRecordDefinition(_recordWithBothCombinedAndSingleForeignKeyDef)
                                  .WithName("Id")
                                  .IsPartOfPrimaryKey(true)
                                  .Build();
            _foreignKeyMessageIdFieldDef = new AddmlFieldDefinitionBuilder()
                                           .WithRecordDefinition(_recordWithBothCombinedAndSingleForeignKeyDef)
                                           .WithName("MessageId")
                                           .Build();
            _foreignKeyAttachmentNumberFieldDef = new AddmlFieldDefinitionBuilder()
                                                  .WithRecordDefinition(_recordWithBothCombinedAndSingleForeignKeyDef)
                                                  .WithName("AttachmentNumber")
                                                  .Build();

            addmlForeignKeyAttachment.ForeignKeys.Add(_foreignKeyMessageIdFieldDef);
            addmlForeignKeyAttachment.ForeignKeys.Add(_foreignKeyAttachmentNumberFieldDef);
            addmlForeignKeyAttachment.ForeignKeyReferenceIndexes.Add(_messageIdPrimaryKeyFieldDef.GetIndex());
            addmlForeignKeyAttachment.ForeignKeyReferenceIndexes.Add(_attachmentNumberPrimaryKeyFieldDef.GetIndex());
            addmlForeignKeyAttachment.ForeignKeyReferenceFields.Add(_messageIdPrimaryKeyFieldDef);
            addmlForeignKeyAttachment.ForeignKeyReferenceFields.Add(_attachmentNumberPrimaryKeyFieldDef);

            _foreignKeyDocumentIdFieldDef = new AddmlFieldDefinitionBuilder()
                                            .WithRecordDefinition(_recordWithBothCombinedAndSingleForeignKeyDef)
                                            .WithName("DocumentId")
                                            .Build();

            addmlForeignKeyDocument.ForeignKeys.Add(_foreignKeyDocumentIdFieldDef);
            addmlForeignKeyDocument.ForeignKeyReferenceIndexes.Add(_documentPrimaryKeyFieldDef.GetIndex());
            addmlForeignKeyDocument.ForeignKeyReferenceFields.Add(_documentPrimaryKeyFieldDef);
        }
Exemplo n.º 2
0
        public AddmlFieldDefinition Build()
        {
            if (_addmlRecordDefinition == null)
            {
                _addmlRecordDefinition = new AddmlRecordDefinitionBuilder().Build();
            }

            var addmlFieldDefinition = _addmlRecordDefinition.AddAddmlFieldDefinition(_name,
                                                                                      _startPosition,
                                                                                      _fixedLength,
                                                                                      _dataType,
                                                                                      _isUnique,
                                                                                      _isNullable,
                                                                                      _minLength,
                                                                                      _maxLength,
                                                                                      _foreignKey?.GetIndex(),
                                                                                      _processes,
                                                                                      _codes,
                                                                                      _isPartOfPrimaryKey);

            addmlFieldDefinition.ForeignKey = _foreignKey;
            return(addmlFieldDefinition);
        }