/// <summary> /// Creates relationship mappings for the given type if they match the predicate. /// </summary> /// <param name="predicate">Determines whether a mapping should be created based on the member info.</param> /// <returns><see cref="RelationshipBuilder"/></returns> public RelationshipBuilder <TEntity> AutoMapPropertiesWhere(Func <MemberInfo, bool> predicate) { ConventionMapStrategy strategy = new ConventionMapStrategy(_publicOnly); strategy.RelationshipPredicate = predicate; RelationshipCollection relationships = strategy.MapRelationships(_entityType); MapRepository.Instance.Relationships[_entityType] = relationships; return(new RelationshipBuilder <TEntity>(_fluentEntity, _entityType, relationships)); }
/// <summary> /// Creates column mappings for the given type if they match the predicate. /// </summary> /// <typeparam name="T">The type that is being built.</typeparam> /// <param name="predicate">Determines whether a mapping should be created based on the member info.</param> /// <returns><see cref="ColumnMapConfigurator"/></returns> public ColumnMapBuilder <TEntity> AutoMapPropertiesWhere(Func <MemberInfo, bool> predicate) { ConventionMapStrategy strategy = new ConventionMapStrategy(_publicOnly); strategy.ColumnPredicate = predicate; ColumnMapCollection columns = strategy.MapColumns(_entityType); MapRepository.Instance.Columns[_entityType] = columns; return(new ColumnMapBuilder <TEntity>(_fluentEntity, columns)); }
/// <summary> /// Creates column mappings for the given type if they match the predicate. /// </summary> /// <typeparam name="T">The type that is being built.</typeparam> /// <param name="predicate">Determines whether a mapping should be created based on the member info.</param> /// <returns><see cref="ColumnMapConfigurator"/></returns> public ColumnMapBuilder <T> BuildColumns <T>(Func <MemberInfo, bool> predicate) { Type entityType = typeof(T); ConventionMapStrategy strategy = new ConventionMapStrategy(_publicOnly); strategy.ColumnPredicate = predicate; ColumnMapCollection columns = strategy.MapColumns(entityType); MapRepository.Instance.Columns[entityType] = columns; return(new ColumnMapBuilder <T>(null, columns)); }
/// <summary> /// Creates relationship mappings for the given type if they match the predicate. /// </summary> /// <typeparam name="T">The type that is being built.</typeparam> /// <param name="predicate">Determines whether a mapping should be created based on the member info.</param> /// <returns><see cref="RelationshipBuilder"/></returns> public RelationshipBuilder <T> BuildRelationships <T>(Func <MemberInfo, bool> predicate) { Type entityType = typeof(T); ConventionMapStrategy strategy = new ConventionMapStrategy(_publicOnly); strategy.RelationshipPredicate = predicate; RelationshipCollection relationships = strategy.MapRelationships(entityType); MapRepository.Instance.Relationships[entityType] = relationships; return(new RelationshipBuilder <T>(null, relationships)); }
/// <summary> /// Tries to add a Relationship for the given field name. /// Throws and exception if field cannot be found. /// </summary> private void TryAddRelationshipForField(string fieldName) { // Set strategy to filter for public or private fields ConventionMapStrategy strategy = new ConventionMapStrategy(false); // Find the field that matches the given field name strategy.RelationshipPredicate = mi => mi.Name == fieldName; Relationship relationship = strategy.MapRelationships(typeof(TEntity)).FirstOrDefault(); if (relationship == null) { throw new DataMappingException(string.Format("Could not find the field '{0}' in '{1}'.", fieldName, typeof(TEntity).Name)); } Relationships.Add(relationship); }