Exemplo n.º 1
0
        private MergingEntityMapping BuildEntityMapping(IDictionary <Type, IEntityMapping> mappings, ITermMappingProvider mappingProvider)
        {
            IEntityMapping existingEntityMapping;

            if (!mappings.TryGetValue(mappingProvider.EntityType, out existingEntityMapping))
            {
                mappings[mappingProvider.EntityType] = existingEntityMapping = new MergingEntityMapping(mappingProvider.EntityType);
            }

            var mergingEntityMapping  = existingEntityMapping as MergingEntityMapping;
            var entityMappingProvider = mappingProvider as IEntityMappingProvider;

            if (entityMappingProvider == null)
            {
                return(mergingEntityMapping);
            }

            var term = entityMappingProvider.GetTerm(_qiriMappings);

            if (term != null)
            {
                mergingEntityMapping.Classes.Add(new StatementMapping(entityMappingProvider.GetGraph(_qiriMappings), term));
            }

            return(mergingEntityMapping);
        }
Exemplo n.º 2
0
        private void BuildPropertyMapping(MergingEntityMapping existingEntityMapping, IPropertyMappingProvider propertyMappingProvider)
        {
            if (propertyMappingProvider == null)
            {
                return;
            }

            IConverter valueConverter = null;

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

            var collectionMappingProvider    = propertyMappingProvider as ICollectionMappingProvider;
            IPropertyMapping propertyMapping = collectionMappingProvider != null
                ? CollectionMapping.CreateFrom(existingEntityMapping, collectionMappingProvider, valueConverter, _qiriMappings)
                : PropertyMapping.CreateFrom(existingEntityMapping, propertyMappingProvider, valueConverter, _qiriMappings);

            var existingPropertyMapping = existingEntityMapping.Properties.FirstOrDefault(mapping => mapping.Name == propertyMappingProvider.Property.Name);

            if (existingPropertyMapping != null)
            {
                if (!PropertyMappingEqualityComparer.Default.Equals(propertyMapping, existingPropertyMapping))
                {
                    throw new AmbiguousMappingException(
                              $"Mapping for ${propertyMappingProvider.Property.Name} for type ${existingEntityMapping.Type} is already defined.");
                }

                return;
            }

            existingEntityMapping.Properties.Add(propertyMapping);
        }