Example #1
0
            /// <summary>
            /// Provides a fluent way to manually add relationship mappings for the current entity.
            /// </summary>
            /// <param name="overwriteExistingMappings">
            /// Overwrites existing mappings if true, or appends if false.
            /// Default is true.
            /// </param>
            /// <returns></returns>
            public RelationshipBuilder <TEntity> MapProperties(bool overwriteExistingMappings = true)
            {
                var repos = MapRepository.Instance;

                RelationshipCollection relationships = null;

                if (overwriteExistingMappings)
                {
                    relationships = new RelationshipCollection();
                    repos.Relationships[_entityType] = relationships;
                }
                else
                {
                    if (repos.Columns.ContainsKey(_entityType))
                    {
                        relationships = repos.Relationships[_entityType];
                    }
                    else
                    {
                        relationships = new RelationshipCollection();
                        repos.Relationships[_entityType] = relationships;
                    }
                }

                return(new RelationshipBuilder <TEntity>(_fluentEntity, _entityType, relationships));
            }
Example #2
0
            /// <summary>
            /// Creates a RelationshipBuilder that starts out with no pre-populated relationships.
            /// All relationships must be added manually using the builder.
            /// </summary>
            /// <returns></returns>
            public RelationshipBuilder <TEntity> MapProperties <T>()
            {
                Type entityType = typeof(T);
                RelationshipCollection relationships = new RelationshipCollection();

                MapRepository.Instance.Relationships[entityType] = relationships;
                return(new RelationshipBuilder <TEntity>(_fluentEntity, relationships));
            }
Example #3
0
        /// <summary>
        /// Creates a RelationshipBuilder that starts out with no pre-populated relationships.
        /// All relationships must be added manually using the builder.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public RelationshipBuilder <T> Relationships <T>()
        {
            Type entityType = typeof(T);
            RelationshipCollection relationships = new RelationshipCollection();

            MapRepository.Instance.Relationships[entityType] = relationships;
            return(new RelationshipBuilder <T>(null, relationships));
        }
Example #4
0
 public RelationshipBuilderFor(
     FluentMappings.MappingsFluentEntity <TEntity> fluentEntity,
     Type tEntityType,
     RelationshipCollection relationships,
     string currentPropertyName)
     : base(fluentEntity, tEntityType, relationships)
 {
     _currentPropertyName = currentPropertyName;
 }
Example #5
0
        protected Type _tEntityType;         // This will differ from TEntity if using ForEachEntity mapping

        public RelationshipBuilder(
            FluentMappings.MappingsFluentEntity <TEntity> fluentEntity,
            Type tEntityType,
            RelationshipCollection relationships)
        {
            _fluentEntity = fluentEntity;
            _tEntityType  = tEntityType;
            Relationships = relationships;
        }
Example #6
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));
            }
Example #7
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));
        }