Trying to get my head round automapping. I am having a problem when trying to automap my domain and generate the database. Im sure its something simple im doing wrong.
The problem is, the correct tables are generated, but only the ID field from the base class is present within the generated tables, none of the other fields within the entities are generated.
BaseEntity is in a different namespace to the entities.
Im not sure where to go from here, any ideas?
Here is my mapping configuration:
public static ISessionFactory CreateSessionFactory()
{
return _sessionFactory = Fluently.Configure()
.Database(ConfigureDatabase())
.Mappings(m => m.AutoMappings.Add(CreateMappings()))
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
}
private static IPersistenceConfigurer ConfigureDatabase()
{
return MsSqlConfiguration
.MsSql2008.ShowSql()
.ConnectionString(c => c.FromAppSetting("MSSqlConnectionString"))
.ProxyFactoryFactory<ProxyFactoryFactory>();
}
private static AutoPersistenceModel CreateMappings()
{
return AutoMap.AssemblyOf<Organisation>(new AutomappingConfig())
.Conventions.Add<CascadeConvention>();
}
private static void BuildSchema(Configuration config)
{
new SchemaUpdate(config)
.Execute(false,true);
}
Heres my autoMappingConfig
public class AutomappingConfig : DefaultAutomappingConfiguration
{
public override bool ShouldMap(Type type)
{
return type.Namespace == "Domain.Model" && type.IsClass;
}
}
And all of my entities inherit this base class:
public class BaseEntity<T> where T : BaseEntity<T>
{
public virtual int Id { get; set; }
}
And an example entity:
public class Contact : BaseEntity<Contact>, IAggregateRoot
{
public virtual String Name { get; set; }
public virtual Organisation Organisation { get; set; }
}