public void Save(AUDIO_ALARM entity)
        {
            if (entity.Attachment == null) return;

            manager.ExecTrans(transaction =>
            {
                var orattachbins = redis.As<REL_AALARMS_ATTACHBINS>().GetAll().Where(x => x.AlarmId == entity.Id);
                var orattachuris = redis.As<REL_AALARMS_ATTACHURIS>().GetAll().Where(x => x.AlarmId == entity.Id);
                var attachbin = entity.Attachment as ATTACH_BINARY;
                if (attachbin != null)
                {
                    transaction.QueueCommand(x => x.Store(attachbin));
                    var rattachbin = new REL_AALARMS_ATTACHBINS
                    {
                        Id = keygenerator.GetNext(),
                        AlarmId = entity.Id,
                        AttachmentId = attachbin.Id
                    };

                    redis.MergeAll(rattachbin.ToSingleton(), orattachbins, transaction);
                }
                else redis.RemoveAll(orattachbins, transaction);

                var attachuri = entity.Attachment as ATTACH_URI;
                if (attachuri != null)
                {
                    transaction.QueueCommand(x => x.Store(attachuri));
                    var rattachuri = new REL_AALARMS_ATTACHURIS
                    {
                        Id = keygenerator.GetNext(),
                        AlarmId = entity.Id,
                        AttachmentId = attachuri.Id
                    };

                    redis.MergeAll(rattachuri.ToSingleton(), orattachuris, transaction);
                }
                else redis.RemoveAll(orattachuris, transaction);


                transaction.QueueCommand(x => x.Store(Dehydrate(entity)));
            });
        }
        /// <summary>
        ///     Inserts a new entity or updates an existing one in the repository
        /// </summary>
        /// <param name="alarm">The entity to save</param>
        public void Save(AUDIO_ALARM alarm)
        {
            db.Save(alarm);

            if (alarm.Attachment == null) return;

            var orattachbins = db.Select<REL_AALARMS_ATTACHBINS>(q => q.Id == alarm.Id);
            var orattachuris = db.Select<REL_AALARMS_ATTACHURIS>(q => q.Id == alarm.Id);

            var attachbin = alarm.Attachment as ATTACH_BINARY;
            if (attachbin != null)
            {
                db.Save(attachbin);
                var rattachbin = new REL_AALARMS_ATTACHBINS
                {
                    Id = keygenerator.GetNext(),
                    AlarmId = alarm.Id,
                    AttachmentId = attachbin.Id
                };

                db.MergeAll(rattachbin.ToSingleton(), orattachbins);
            }
            else db.RemoveAll(orattachbins);

            var attachuri = alarm.Attachment as ATTACH_URI;
            if (attachuri != null)
            {
                db.Save(attachuri);
                var rattachuri = new REL_AALARMS_ATTACHURIS
                {
                    Id = keygenerator.GetNext(),
                    AlarmId = alarm.Id,
                    AttachmentId = attachuri.Id
                };

                db.MergeAll(rattachuri.ToSingleton(), orattachuris);
            }
            else db.RemoveAll(orattachuris);
        }