public IDisposable Sync <T>(Dictionary <string, T> entityDic, IEnumerable <XElement> elements, IFromXmlContext ctx, Action <T, XElement> setXml)
            where T : Entity, new()
        {
            var xmlDic = elements.ToDictionaryEx(a => a.Attribute("BpmnElementId").Value);

            Synchronizer.Synchronize(
                xmlDic,
                entityDic,
                createNew: (bpmnId, xml) =>
            {
                var entity = new T();
                setXml(entity, xml);
                entityDic.Add(bpmnId, ctx.SaveMaybe(entity));
            },
                removeOld: null,
                merge: null);


            return(new Disposable(() =>
            {
                Synchronizer.Synchronize(
                    xmlDic,
                    entityDic,
                    createNew: null,
                    removeOld: (bpmnId, entity) => ctx.DeleteMaybe(entity),
                    merge: (bpmnId, xml, entity) =>
                {
                    setXml(entity, xml);
                    ctx.SaveMaybe(entity);
                });
            }));
        }