private static IEntityMapping BuildMapping <TEntity>(this ICollection <ITermMappingProvider> mappingProviders, out IPropertyMapping firstPropertyMapping)
        {
            firstPropertyMapping = null;
            var entityMapping = new MergingEntityMapping(typeof(TEntity));

            foreach (var mappingProvider in mappingProviders)
            {
                mappingProvider.Accept(MappingVisitors);
                var entityMappingProvider = mappingProvider as IEntityMappingProvider;
                if (entityMappingProvider != null)
                {
                    entityMapping.Classes.Add(new StatementMapping(entityMappingProvider.GetGraph(QIriMappings), entityMappingProvider.GetTerm(QIriMappings)));
                    continue;
                }

                var propertyMappingProvider = mappingProvider as IPropertyMappingProvider;
                if (propertyMappingProvider == null)
                {
                    continue;
                }

                ILiteralConverter valueConverter = null;
                if (propertyMappingProvider.ValueConverterType != null)
                {
                    valueConverter = ConverterProvider.FindConverter(propertyMappingProvider.ValueConverterType);
                }

                var collectionMappingProvider = mappingProvider as ICollectionMappingProvider;
                var propertyMapping           = (collectionMappingProvider != null
                    ? CollectionMapping.CreateFrom(entityMapping, collectionMappingProvider, valueConverter, QIriMappings)
                    : PropertyMapping.CreateFrom(entityMapping, propertyMappingProvider, valueConverter, QIriMappings));
                entityMapping.Properties.Add(propertyMapping);
                if (firstPropertyMapping == null)
                {
                    firstPropertyMapping = propertyMapping;
                }
            }

            return(entityMapping);
        }