I am using FluentNHibernate. I do not use auto-mapping. I have a base class that is a subclass. When I request the base class, it makes an additional request to the subclass. Here's a (far-fetched) example of what I'm doing:
public class Foo { int Id; string SomeValue; }
I create another class that represents the audit record of the first, and I inherit it:
public class FooAudit : Foo { DateTime DateModified; }
I create separate mappings for each that go to their own tables:
public class FooMap : ClassMap<Foo> { public FooAuditMap() { Table("Foo"); Id(x => x.Id).Column("FOO_ID"); Map(x => x.SomeValue).Column("SOME_VALUE"); } } public class FooAuditMap : ClassMap<FooAuditMap> { public FooAuditMap() { Table("FooAudit"); CompositeId() .KeyProperty(x => x.DateModified, c => c.ColumnName("AUDIT_DATE")); .KeyProperty(x => x.Id, c => c.ColumnName("FOO_ID")); Map(x => x.SomeValue).Column("SOME_VALUE"); } }
I am running a query against Foo:
public virtual IEnumerable<Foo> List() { using (var session = SessionFactory.OpenSession()) { return session.CreateCriteria<Foo>().List<Foo>(); } }
which then hits the DB twice, once to execute this query against Foo and again in FooAudit.
Why is he making two requests? I generated HBM files and absolutely nothing binds these classes.
EDIT: for completeness, it looks like a bootstrap script.
public static ISessionFactory CreateSessionFactory() { return Fluently .Configure() .Database ( FluentNHibernate.Cfg .Db.MsSqlConfiguration.MsSql2005 .ConnectionString(GetConnectionString()) ) .Mappings(m => m .FluentMappings.AddFromAssemblyOf<Foo>() .Conventions.Add(typeof(EnumConvention))) .BuildSessionFactory(); }
source share