public virtual IEnumerable<InsertRecord> GetPrimaryKeyOperations(IEnumerable<AbstractRepositoryOperation> peers)
        {
            InsertRecordService.Logger.Debug("Entering GetPrimaryKeyOperations");

            peers = peers.ToList();

            InsertRecordService.Logger.Debug($"peer objects: {peers.GetRecordTypesString()}");

            IEnumerable<InsertRecord> result = peers.Where(
                peer =>
                {
                    var pkRecord = peer as InsertRecord;

                    bool peerResult = pkRecord != null
                                  && this.recordReference.PrimaryKeyReferences.Any(
                                      primaryKeyReference => primaryKeyReference == pkRecord.RecordReference);

                    return peerResult;

                }).Cast<InsertRecord>().ToList();

            InsertRecordService.Logger.Debug(
                $"Exiting GetPrimaryKeyOperations. result: {result.GetRecordTypesString()}");

            return result;
        }
        public virtual void WritePrimaryKeyOperations(IWritePrimitives writer, IEnumerable<AbstractRepositoryOperation> primaryKeyOperations,
            CircularReferenceBreaker breaker, Counter order, AbstractRepositoryOperation[] orderedOperations)
        {
            InsertRecordService.Logger.Debug("Entering WritePrimaryKeyOperations");

            primaryKeyOperations = primaryKeyOperations.ToList();

            InsertRecordService.Logger.Debug($"primaryKeyOperations: {primaryKeyOperations.GetRecordTypesString()}");
            InsertRecordService.Logger.Debug($"order: {order.Value}");

            InsertRecordService.Logger.Debug($"orderedOperations: {orderedOperations.GetRecordTypesString()}");

            primaryKeyOperations.ToList().ForEach(o => o.Write(breaker, writer, order, orderedOperations));

            InsertRecordService.Logger.Debug("Exiting WritePrimaryKeyOperations");
        }
        public virtual IEnumerable<ExtendedColumnSymbol> GetForeignKeyColumns(IEnumerable<InsertRecord> primaryKeyOperations)
        {
            InsertRecordService.Logger.Debug("Entering GetForeignKeyVariables");

            primaryKeyOperations = primaryKeyOperations.ToList();

            InsertRecordService.Logger.Debug(
                $"primaryKeyOperations: {primaryKeyOperations.GetRecordTypesString()}");

            List<IEnumerable<ColumnSymbol>> keyTableList =
                primaryKeyOperations.Select(o => o.GetPrimaryKeySymbols()).ToList();

            InsertRecordService.Logger.Debug($"keyTableList: {Helper.ToCompositeString(keyTableList.Select(kt => string.Join(", ", kt)))}");

            IEnumerable<PropertyAttribute<ForeignKeyAttribute>> foreignKeyPropertyAttributes =
                this.attributeDecorator.GetPropertyAttributes<ForeignKeyAttribute>(this.recordReference.RecordType);

            var foreignKeys = foreignKeyPropertyAttributes.Select(fkpa =>
            {
                InsertRecordService.Logger.Debug($"fkpa (foreign Key Property Arttribute) : {fkpa}");

                ColumnSymbol pkColumnMatch = null;

                bool isForeignKeyPrimaryKeyMatch = keyTableList.Any(pkTable =>

                    pkTable.Any(pk =>

                        this.attributeDecorator.GetTableType(fkpa.Attribute, this.recordReference.RecordType) == (pkColumnMatch = pk).TableType
                        && fkpa.Attribute.PrimaryKeyName.Equals(pk.ColumnName, StringComparison.Ordinal)
                        )
                    );

                if (this.enforceKeyReferenceCheck && !isForeignKeyPrimaryKeyMatch)
                {
                    InsertRecordService.Logger.Debug(
                        $"Key reference check branch taken. Referential integrity check failed. Foreign Key PropertyAttribute : {fkpa}");

                    throw new InserRecordServiceException(Messages.ForeignKeyRecordWithNoPrimaryKeyRecord,
                        fkpa.PropertyInfo.DeclaringType.FullName, fkpa.PropertyInfo.Name);
                }

                return
                    new
                    {
                        PkColumnValue =

                            this.recordReference.IsExplicitlySet(fkpa.PropertyInfo)

                                ? fkpa.PropertyInfo.GetValue(this.recordReference.RecordObject)

                                : isForeignKeyPrimaryKeyMatch

                                    ? pkColumnMatch.Value

                                    : Helper.GetDefaultValue(fkpa.PropertyInfo.PropertyType),

                        FkPropertyAttribute = fkpa
                    };
            });

            IEnumerable<ExtendedColumnSymbol> result =
                foreignKeys.Select(
                    fk =>
                        new ExtendedColumnSymbol
                        {
                            TableType = fk.FkPropertyAttribute.PropertyInfo.DeclaringType,
                            ColumnName = Helper.GetColumnName(fk.FkPropertyAttribute.PropertyInfo, this.attributeDecorator),
                            Value = fk.PkColumnValue,
                            PropertyAttribute = fk.FkPropertyAttribute,
                        }).ToList();

            InsertRecordService.Logger.Debug($"Entering GetForeignKeyVariables. Result: {Helper.ToCompositeString(result)}");
            return result;
        }