public static Association ParseJsonAssociation(dynamic s, IEnumerable<TiplocCode> tiplocs)
        {
            var a = new Association();
            a.TransactionType = TransactionTypeField.ParseDataString(DynamicValueToString(s.transaction_type));
            a.MainTrainUid = StringField.ParseDataString(DynamicValueToString(s.main_train_uid));
            a.AssocTrainUid = StringField.ParseDataString(DynamicValueToString(s.assoc_train_uid));
            a.StartDate = DynamicValueToDateTime(s.assoc_start_date);
            string tiplocCode = DynamicValueToString(s.location);
            TiplocCode tiploc = tiplocs.FirstOrDefault(t => t.Tiploc.Equals(tiplocCode, StringComparison.CurrentCultureIgnoreCase));
            if (tiploc == null)
            {
                throw new TiplocNotFoundException(tiplocCode)
                {
                    Code = tiplocCode
                };
            }
            a.Location = tiploc;
            switch (a.TransactionType)
            {
                case TransactionType.Create:
                    a.EndDate = DynamicValueToDateTime(s.assoc_end_date);
                    a.Schedule = ScheduleField.ParseDataString(DynamicValueToString(s.assoc_days));
                    a.STPIndicator = STPIndicatorField.ParseDataString(DynamicValueToString(s.CIF_stp_indicator));
                    a.AssociationType = TrainAssociationTypeField.ParseDataString(DynamicValueToString(s.category));
                    a.DateType = TrainAssociationDateField.ParseDataString(DynamicValueToString(s.date_indicator));
                    break;
            }

            return a;
        }
        public Guid AddAssociation(Association a)
        {
            const string sql = @"
                INSERT INTO [dbo].[TrainAssociation]
                           ([MainTrainUid]
                           ,[AssocTrainUid]
                           ,[StartDate]
                           ,[EndDate]
                           ,[AppliesMonday]
                           ,[AppliesTuesday]
                           ,[AppliesWednesday]
                           ,[AppliesThursday]
                           ,[AppliesFriday]
                           ,[AppliesSaturday]
                           ,[AppliesSunday]
                           ,[LocationTiplocId]
                           ,[AssociationDate]
                           ,[AssociationType]
                           ,[STPIndicatorId]
                           ,[Deleted])
                    OUTPUT [inserted].[AssociationId]
                     VALUES
                           (@mainTrainUid
                           ,@assocTrainUid
                           ,@startDate
                           ,@endDate
                           ,@appliesMonday
                           ,@appliesTuesday
                           ,@appliesWednesday
                           ,@appliesThursday
                           ,@appliesFriday
                           ,@appliesSaturday
                           ,@appliesSunday
                           ,@locationTiplocId
                           ,@associationDate
                           ,@associationType
                           ,@stpIndicatorId
                           ,@deleted)";

            Guid id = ExecuteInsert(sql, new
            {
                mainTrainUid = a.MainTrainUid,
                assocTrainUid = a.AssocTrainUid,
                startDate = a.StartDate,
                endDate = a.EndDate,
                appliesMonday = GetBoolean(a.Schedule, (s) => s.Monday),
                appliesTuesday = GetBoolean(a.Schedule, (s) => s.Tuesday),
                appliesWednesday = GetBoolean(a.Schedule, (s) => s.Wednesday),
                appliesThursday = GetBoolean(a.Schedule, (s) => s.Thursday),
                appliesFriday = GetBoolean(a.Schedule, (s) => s.Friday),
                appliesSaturday = GetBoolean(a.Schedule, (s) => s.Saturday),
                appliesSunday = GetBoolean(a.Schedule, (s) => s.Sunday),
                locationTiplocId = a.Location.TiplocId,
                associationDate = a.DateType,
                associationType = a.AssociationType,
                stpIndicatorId = a.STPIndicator,
                deleted = a.TransactionType == TransactionType.Delete
            });
            a.AssociationId = id;
            return id;
        }