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


C# ConventionModelMapper.IsOneToMany方法代码示例

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


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

示例1: ConventionsMapping

		static void ConventionsMapping(ConventionModelMapper mapper)
		{
			mapper.IsOneToMany((MemberInfo member, Boolean isLikely) =>
			{
				Type sourceType = member.DeclaringType;
				Type destinationType = member.GetMemberFromDeclaringType().GetPropertyOrFieldType();

				//check if the property is of a generic collection type
				if ((destinationType.IsGenericCollection() == true) && (destinationType.GetGenericArguments().Length == 1))
				{
					Type destinationEntityType = destinationType.GetGenericArguments().Single();

					//check if the type of the generic collection property is an entity
					if (mapper.ModelInspector.IsEntity(destinationEntityType) == true)
					{
						//check if there is an equivalent property on the target type that is also a generic collection and points to this entity
						PropertyInfo collectionInDestinationType = destinationEntityType.GetProperties().Where(x => (x.PropertyType.IsGenericCollection() == true) && (x.PropertyType.GetGenericArguments().Length == 1) && (x.PropertyType.GetGenericArguments().Single() == sourceType)).SingleOrDefault();

						if (collectionInDestinationType != null)
						{
							return (false);
						}
					}
				}

				return (true);
			});

			mapper.IsManyToMany((MemberInfo member, Boolean isLikely) =>
			{
				//a relation is many to many if it isn't one to many
				Boolean isOneToMany = mapper.ModelInspector.IsOneToMany(member);
				return (!isOneToMany);
			});

			mapper.BeforeMapClass += (IModelInspector modelInspector, Type type, IClassAttributesMapper classCustomizer) =>
			{
				classCustomizer.Id(x =>
				{
					//set the hilo generator
					x.Generator(Generators.HighLow);
				});
			};

			mapper.BeforeMapManyToMany += (IModelInspector modelInspector, PropertyPath member, IManyToManyMapper collectionRelationManyToManyCustomizer) =>
			{
				Type destinationEntityType = member.LocalMember.GetPropertyOrFieldType().GetGenericArguments().First();
				//set the mapping table column names from each source entity name plus the _Id sufix
				collectionRelationManyToManyCustomizer.Column(destinationEntityType.Name + "_Id");
			};

			mapper.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,代码行数:68,代码来源:Program.cs


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