
Untitled
By: a guest on
Sep 16th, 2012 | syntax:
None | size: 1.08 KB | hits: 16 | expires: Never
private static HbmMapping InitializeTypes()
{
var mapper = new ConventionModelMapper();
mapper.BeforeMapClass += (mi, t, map) =>
{
map.Table(t.Name.Remove(t.Name.Length - 6));
map.Id(x =>
{
x.Column("Id");
x.Generator(Generators.Assigned);
});
};
mapper.BeforeMapProperty += (mi, t, map) => map.Column(t.ToColumnName());
Func<Type, bool, bool> matchRootEntity = (type, wasDeclared) => typeof(EntityTypeBase) == type.BaseType;
var entities = Assembly.GetExecutingAssembly().GetExportedTypes()
.Where(t => typeof(EntityTypeBase).IsAssignableFrom(t) && !(typeof(EntityTypeBase) == t)).ToList();
mapper.IsEntity((type, wasDeclared) => entities.Contains(type));
mapper.IsRootEntity(matchRootEntity);
return mapper.CompileMappingFor(entities);
}