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)); } }; }