예제 #1
0
        /// <summary>
        /// Maps a many to one relationship
        /// </summary>
        /// <param name="modelInspector">The model inspector</param>
        /// <param name="property">The property to map</param>
        /// <param name="mapper">The property mapper</param>
        private void MapManyToOne(IModelInspector modelInspector, PropertyPath property, IManyToOneMapper mapper)
        {
            Type       targetEntityType = property.LocalMember.GetPropertyOrFieldType();
            Type       sourceEntityType = property.GetContainerEntity(modelInspector);
            MemberInfo member           = property.PreviousPath != null ? property.PreviousPath.LocalMember : property.LocalMember;

            var targetEntityIDProperty = modelInspector.GetIdentifierMember(targetEntityType);
            var foreignKeyProperty     = property.LocalMember;

            string columnName     = null;
            string foreignKeyName = null;
            var    one            = modelInspector.IsOneToOne(property.LocalMember);


            if (MatchOneToOneComponent(property, modelInspector))
            {
                columnName     = namingEngine.ToComponentForeignKeyColumnName(foreignKeyProperty, member, targetEntityIDProperty);
                foreignKeyName = namingEngine.ToForeignKeyName(sourceEntityType, targetEntityType, member, targetEntityIDProperty);
            }
            else
            {
                columnName     = namingEngine.ToForeignKeyColumnName(property.LocalMember, targetEntityIDProperty);
                foreignKeyName = namingEngine.ToForeignKeyName(sourceEntityType, targetEntityType, foreignKeyProperty, targetEntityIDProperty);
            }

            mapper.Column(columnName);
            mapper.ForeignKey(foreignKeyName);
        }
예제 #2
0
        /// <summary>
        /// Indicates if a given property matches a one to one component relationship
        /// </summary>
        /// <param name="property">The property</param>
        /// <param name="modelInspector">An instance of the current model inspector</param>
        /// <returns>True if the property matches a one to one component relationship, false if not</returns>
        private bool MatchOneToOneComponent(PropertyPath property, IModelInspector modelInspector)
        {
            bool result = false;
            var  one    = modelInspector.IsOneToOne(property.LocalMember.DeclaringType);

            if (modelInspector.IsComponent(property.LocalMember.DeclaringType))
            {
                result = (property.PreviousPath != null) && !property.PreviousPath.LocalMember.GetPropertyOrFieldType().IsGenericCollection();
            }

            return(result);
        }