private string BuildMappingXml(IEnumerable <Type> typesToMap)
        {
            var builder = new XDocumentBuilder("urn:nhibernate-mapping-2.2");

            builder.Element("hibernate-mapping")
            .Attribute("default-cascade", "save-update");


            foreach (var type in typesToMap)
            {
                MapType(type, builder);
            }

            builder
            .EndElement();


            var xml = builder.XDocument.ToString();

            return(xml);
        }
        private void MapType(Type type, XDocumentBuilder builder)
        {
            if (IsBaseType(type))
            {
                MapEntityProperties(type, builder);
            }
            else
            {
                MapSubclass(type, builder);
            }

            var properties = from property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public)
                             where (!property.IsDefined(typeof(NonPersistentAttribute), false)) &&
                             property.DeclaringType == type
                             select property;


            foreach (var property in properties)
            {
                MapProperty(property, builder);
            }

            builder.EndElement();
        }