I've just started using Fluent NHibernate and have run into the following problem trying to automap my entities:
public interface IDataEntity {}
public abstract class PhysicalEntity : IDataEntity {
public virtual int Id { get; set; }
public virtual string Name { get; set; }
}
public class Mine : PhysicalEntity {
public virtual string MineString { get; set; }
}
private static ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(c => c.FromConnectionStringWithKey("CSMID_FNH")))
.Mappings(m =>
m.AutoMappings.Add(
AutoMap.AssemblyOf<Mine>()
.Where(t => t.Namespace == "DAL.DomainModel" && t.IsClass && !t.Name.EndsWith("Attribute") )
.IgnoreBase<PhysicalEntity>()))
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
}
Now if I remove the reference to the IDataEntity interface, the automapping works. I tried inserting an ID field in the interface however this results in a NHibernate runtime error, as does telling the auto map to ignore the IDataEntity type. What am I missing here? I'd really like all the classes in my domain to inherit from IDataEntity.