Example #1
0
        private static HbmMapping GetMappings(IEnumerable <Assembly> mappingsAssemblies)
        {
            //Using the built-in auto-mapper
            var mapper = new ConventionModelMapper();

            DefineBaseClass(mapper);
            var allEntities = new List <Type>();

            foreach (var mappingsAssembly in mappingsAssemblies)
            {
                allEntities.AddRange(mappingsAssembly.GetTypes().Where(
                                         t => BaseEntityToIgnore.IsAssignableFrom(t) &&
                                         t != BaseEntityToIgnore &&
                                         !t.IsInterface
                                         ).ToList());
            }
            mapper.AddAllManyToManyRelations(allEntities);
            mapper.ApplyNamingConventions();
            if (MapAllEnumsToStrings)
            {
                mapper.MapAllEnumsToStrings();
            }
            if (AutoMappingOverride != null)
            {
                AutoMappingOverride(mapper);
            }
            OverrideByClassMapping(mapper, mappingsAssemblies);

            var mapping = mapper.CompileMappingFor(allEntities);

            //ShowOutputXmlMappings(mapping);
            return(mapping);
        }
Example #2
0
 private void DefineBaseClass(ConventionModelMapper mapper)
 {
     if (BaseEntityToIgnore == null)
     {
         return;
     }
     mapper.IsEntity((type, declared) =>
                     BaseEntityToIgnore.IsAssignableFrom(type) &&
                     BaseEntityToIgnore != type &&
                     !type.IsInterface);
     mapper.IsRootEntity((type, declared) => type.BaseType == BaseEntityToIgnore);
 }
Example #3
0
 private static void DefineBaseClass(ConventionModelMapper mapper)
 {
     if (BaseEntityToIgnore == null)
     {
         BaseEntityToIgnore = typeof(BaseDomainObject);
     }
     mapper.IsEntity((type, declared) =>
                     BaseEntityToIgnore.IsAssignableFrom(type) &&
                     BaseEntityToIgnore != type &&
                     !type.IsInterface);
     mapper.IsRootEntity((type, declared) => type.BaseType == BaseEntityToIgnore);
     //mapper.IsTablePerClassHierarchy((type, declared) =>true);
 }