Пример #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));
            }
Пример #2
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));
        }
Пример #3
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);
        }