Ejemplo n.º 1
0
            /// <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));
            }
Ejemplo n.º 2
0
            /// <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));
            }
Ejemplo n.º 3
0
        /// <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));
        }
Ejemplo n.º 4
0
        /// <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));
        }
Ejemplo n.º 5
0
        /// <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);
        }