Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 16th, 2012  |  syntax: None  |  size: 1.08 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. private static HbmMapping InitializeTypes()
  2. {
  3.     var mapper = new ConventionModelMapper();
  4.     mapper.BeforeMapClass += (mi, t, map) =>
  5.                              {
  6.                                 map.Table(t.Name.Remove(t.Name.Length - 6));
  7.                                 map.Id(x =>
  8.                                            {
  9.                                                 x.Column("Id");
  10.                                                 x.Generator(Generators.Assigned);
  11.                                             });
  12.                              };
  13.     mapper.BeforeMapProperty += (mi, t, map) => map.Column(t.ToColumnName());
  14.  
  15.     Func<Type, bool, bool> matchRootEntity = (type, wasDeclared) => typeof(EntityTypeBase) == type.BaseType;
  16.  
  17.     var entities = Assembly.GetExecutingAssembly().GetExportedTypes()
  18.                        .Where(t => typeof(EntityTypeBase).IsAssignableFrom(t) && !(typeof(EntityTypeBase) == t)).ToList();
  19.  
  20.     mapper.IsEntity((type, wasDeclared) => entities.Contains(type));
  21.     mapper.IsRootEntity(matchRootEntity);
  22.    
  23.     return mapper.CompileMappingFor(entities);
  24. }