private XmlDocument generateDefaultRevisionInfoXmlMapping()
        {
            XmlDocument document = new XmlDocument();//ORIG: DocumentHelper.createDocument();

            XmlElement class_mapping = MetadataTools.CreateEntity(document, new AuditTableData(null, null, null, null), null);

            class_mapping.SetAttribute("name", revisionInfoEntityName);
            class_mapping.SetAttribute("table", "REVINFO");

            XmlElement idProperty = MetadataTools.AddNativelyGeneratedId(document, class_mapping, revisionInfoIdData.Name,
                                                                         revisionPropType);
            //ORIG: MetadataTools.addColumn(idProperty, "REV", -1, 0, 0, null);
            XmlElement col = idProperty.OwnerDocument.CreateElement("column");

            col.SetAttribute("name", "REV");
            //idProperty should have a "generator" node otherwise sth. is wrong.
            idProperty.InsertBefore(col, idProperty.GetElementsByTagName("generator")[0]);

            XmlElement timestampProperty = MetadataTools.AddProperty(class_mapping, revisionInfoTimestampData.Name,
                                                                     revisionInfoTimestampType.Name, true, false);

            MetadataTools.AddColumn(timestampProperty, "REVTSTMP", -1, 0, 0, SqlTypeFactory.DateTime.ToString());

            return(document);
        }
        private XDocument generateDefaultRevisionInfoXmlMapping()
        {
            var document = new XDocument();

            var classMapping = MetadataTools.CreateEntity(document,
                                                          new AuditTableData(null, null, _globalCfg.DefaultSchemaName, _globalCfg.DefaultCatalogName),
                                                          null, false);

            classMapping.Add(new XAttribute("name", revisionInfoEntityName), new XAttribute("table", "REVINFO"));

            MetadataTools.AddNativelyGeneratedId(classMapping, revisionInfoIdData.Name, revisionPropType);

            var timestampProperty = MetadataTools.AddProperty(classMapping, revisionInfoTimestampData.Name, revisionInfoTimestampType.Name, true, false, null);

            MetadataTools.AddColumn(timestampProperty, "REVTSTMP", -1, -1, -1, null, false);

            if (_globalCfg.IsTrackEntitiesChangedInRevisionEnabled)
            {
                generateEntityNamesTrackingTableMapping(classMapping, "ModifiedEntityNames",
                                                        _globalCfg.DefaultSchemaName, _globalCfg.DefaultCatalogName,
                                                        "REVCHANGES", "REV",
                                                        "ENTITYNAME", "string");
            }

            return(document);
        }
        /// <summary>
        /// Adds a <![CDATA[<many-to-one>]]> mapping to the revision entity as an endrevision.
        /// Also, if <see cref="AuditEntitiesConfiguration.IsRevisionEndTimestampEnabled"/> set, adds a timestamp when the revision is no longer valid.
        /// </summary>
        public void AddExtraRevisionMapping(XElement classMapping, XElement revisionInfoRelationMapping)
        {
            var verEntCfg = _auditConfiguration.AuditEntCfg;
            var manyToOne = MetadataTools.AddManyToOne(classMapping, verEntCfg.RevisionEndFieldName, verEntCfg.RevisionInfoEntityAssemblyQualifiedName, true, true);

            manyToOne.Add(revisionInfoRelationMapping.Elements());
            MetadataTools.AddOrModifyColumn(manyToOne, verEntCfg.RevisionEndFieldName);

            if (verEntCfg.IsRevisionEndTimestampEnabled)
            {
                const string revisionInfoTimestampSqlType = "Timestamp";
                MetadataTools.AddProperty(classMapping, verEntCfg.RevisionEndTimestampFieldName, revisionInfoTimestampSqlType, true, true, false, null);
            }
        }