当前位置: 首页>>代码示例>>C#>>正文


C# IModelInspector.IsManyToMany方法代码示例

本文整理汇总了C#中IModelInspector.IsManyToMany方法的典型用法代码示例。如果您正苦于以下问题:C# IModelInspector.IsManyToMany方法的具体用法?C# IModelInspector.IsManyToMany怎么用?C# IModelInspector.IsManyToMany使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IModelInspector的用法示例。


在下文中一共展示了IModelInspector.IsManyToMany方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BeforeMappingCollectionConvention

        private void BeforeMappingCollectionConvention(IModelInspector inspector, PropertyPath member, ICollectionPropertiesMapper customizer)
        {
            if (inspector.IsManyToMany(member.LocalMember))
                customizer.Table(member.ManyToManyIntermediateTableName());

            customizer.Key(k => k.Column(DetermineKeyColumnName(inspector, member)));
        }
开发者ID:MatthewRudolph,项目名称:Airy,代码行数:7,代码来源:ModelMapperWithNamingConventions.cs

示例2: BeforeMapSet

		protected virtual new void BeforeMapSet(IModelInspector modelInspector, PropertyPath member, ISetPropertiesMapper propertyCustomizer)
		{
			if (modelInspector.IsManyToMany(member.LocalMember) == true)
			{
				propertyCustomizer.Key(x => x.Column(member.LocalMember.DeclaringType.Name + "_Id"));

				Type sourceType = member.LocalMember.DeclaringType;
				Type destinationType = member.LocalMember.GetPropertyOrFieldType().GetGenericArguments().First();
				String [] names = new Type[] { sourceType, destinationType }.Select(x => x.Name).OrderBy(x => x).ToArray();

				//set inverse on the relation of the alphabetically first entity name
				propertyCustomizer.Inverse(sourceType.Name == names.First());
				//set mapping table name from the entity names in alphabetical order
				propertyCustomizer.Table(String.Join("_", names));
			}
		}
开发者ID:rjperes,项目名称:DevelopmentWithADot.NHibernateConventions,代码行数:16,代码来源:ManyToManyConventionModelMapper.cs

示例3: MapCollection

        /// <summary>
        /// Maps a collection of components or entities
        /// </summary>
        /// <param name="modelInspector">The model inspector</param>
        /// <param name="property">The property to map</param>
        /// <param name="mapper">The collections mapper</param>
        private void MapCollection(IModelInspector modelInspector, PropertyPath property, ICollectionPropertiesMapper mapper)
        {
            Type sourceType = property.GetContainerEntity(modelInspector);
            Type targetType = property.LocalMember.GetPropertyOrFieldType().DetermineCollectionElementType();

            var primaryKeyProperty = modelInspector.GetIdentifierMember(sourceType);
            var foreignKeyProperty = property.LocalMember;
            string foreignKeyColumnName = null;
            string foreignKeyName = null;
            string tableName = null;
            string schemaName = null;

            if (modelInspector.IsEntity(targetType))
            {
                // Entity Relationship Mapping
                if (modelInspector.IsManyToMany(property.LocalMember))
                {
                    // Many to many
                    foreignKeyColumnName = namingEngine.ToManyToManyForeignKeyColumnName(sourceType, primaryKeyProperty);
                    foreignKeyName = namingEngine.ToManyToManyForeignKeyName(sourceType, targetType, sourceType, primaryKeyProperty);
                    tableName = namingEngine.ToManyToManyTableName(sourceType, targetType);
                    schemaName = namingEngine.ToSchemaName(sourceType, targetType);
                }
                else
                {
                    // One to Many
                    foreignKeyColumnName = namingEngine.ToForeignKeyColumnName(sourceType, primaryKeyProperty);
                    foreignKeyName = namingEngine.ToForeignKeyName(targetType, sourceType, sourceType, primaryKeyProperty);
                }
            }
            else if (IsElement(targetType))
            {
                // Element mapping
                foreignKeyColumnName = namingEngine.ToForeignKeyColumnName(sourceType, primaryKeyProperty);
                foreignKeyName = namingEngine.ToComponentForeignKeyName(targetType, sourceType, foreignKeyProperty, primaryKeyProperty);
                tableName = namingEngine.ToElementTableName(sourceType, targetType, property.LocalMember);
                schemaName = namingEngine.ToSchemaName(sourceType, targetType);
            }
            else
            {
                // Component Relationship Mapping
                foreignKeyColumnName = namingEngine.ToForeignKeyColumnName(sourceType, primaryKeyProperty);
                foreignKeyName = namingEngine.ToComponentForeignKeyName(targetType, sourceType, foreignKeyProperty, primaryKeyProperty);
                tableName = namingEngine.ToComponentTableName(sourceType, targetType, property.LocalMember);
                schemaName = namingEngine.ToSchemaName(sourceType, targetType);
            }

            // Mapping
            mapper.Schema(schemaName);
            mapper.Table(tableName);
            mapper.Key(k =>
            {
                k.Column(foreignKeyColumnName);
                k.ForeignKey(foreignKeyName);
            });
        }
开发者ID:HomeroThompson,项目名称:firehawk,代码行数:62,代码来源:MappingEngine.cs

示例4: OnBeforeMappingCollectionConvention

        protected virtual void OnBeforeMappingCollectionConvention(IModelInspector modelinspector, PropertyPath member, ICollectionPropertiesMapper collectionPropertiesCustomizer)
        {
            if (modelinspector.IsManyToMany(member.LocalMember))
            {
                collectionPropertiesCustomizer.Table(member.ManyToManyIntermediateTableName("To"));
            }

            if (modelinspector.IsSet(member.LocalMember))
            {
                // If otherside has many-to-one, make it inverse, if not specify foreign key on Key element
                MemberInfo oneToManyProperty = member.OneToManyOtherSideProperty();
                IEnumerable<MemberInfo> candidatesManyToOne =
                    MembersProvider
                        .GetRootEntityMembers(oneToManyProperty.DeclaringType)
                        .Where(modelinspector.IsManyToOne);
                if (candidatesManyToOne.Any(mi => mi.MemberType() == member.LocalMember.DeclaringType))
                {
                    collectionPropertiesCustomizer.Inverse(true);
                }
                else
                {
                    Contract.Assert(oneToManyProperty.DeclaringType != null, "otherSideProperty.DeclaringType != null");
                    collectionPropertiesCustomizer.Key(k => k.ForeignKey(string.Format("FK_{0}_{1}", oneToManyProperty.DeclaringType.Name, oneToManyProperty.Name)));
                }
            }

            collectionPropertiesCustomizer.Key(k => k.Column(GetKeyColumnName(modelinspector, member)));
        }
开发者ID:NickJoosens,项目名称:net-ppwcode-vernacular-nhibernate,代码行数:28,代码来源:SimpleModelMapper.cs

示例5: BeforeMappingCollectionConvention

        /// <summary>
        /// Sets the following conventions:
        /// 1) Foreign key fields are named as the property name suffixed by the value of _foreignKeyColumnSuffix.
        /// 2) Many to Many link tables are named as the object type names sorted alphabetically with the _manyToManyLinkTableInsert inserted inbetween them.
        /// </summary>
        private void BeforeMappingCollectionConvention(IModelInspector inspector, PropertyPath member, ICollectionPropertiesMapper customizer)
        {
            string tableName;
            if (inspector.IsManyToMany(member.LocalMember))
            {
                tableName = GetManyToManyLinkTableName(member);
                customizer.Table(tableName);
            }
            else
            {
                tableName = member.GetCollectionElementType().Name;
            }

            string columnName = GetKeyColumnName(inspector, member);
            string foreignKeyName = string.Format("{0}{1}_{2}", _foreignKeyNamePrefix, tableName, columnName);
            customizer.Key(k =>
            {
                k.Column(columnName);
                k.ForeignKey(foreignKeyName);
            });
        }
开发者ID:MatthewRudolph,项目名称:Airy,代码行数:26,代码来源:DefaultModelMapper.cs


注:本文中的IModelInspector.IsManyToMany方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。