Пример #1
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));
            }
Пример #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 <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));
        }
Пример #3
0
        /// <summary>
        /// Tries to add a ColumnMap for the given field name.
        /// Throws and exception if field cannot be found.
        /// </summary>
        private void TryAddColumnMapForField(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.ColumnPredicate = mi => mi.Name == fieldName;
            ColumnMap columnMap = strategy.MapColumns(typeof(TEntity)).FirstOrDefault();

            if (columnMap == null)
            {
                throw new DataMappingException(string.Format("Could not find the field '{0}' in '{1}'.",
                                                             fieldName,
                                                             typeof(TEntity).Name));
            }
            MappedColumns.Add(columnMap);
        }