0

I am using auto-mapping with flent-hibernate for mapping. I would like if there is a way to set the reference property to be as 'lazy-loading' using IConvention or similar, rather than using separate mapping class?

Heinnge
  • 858
  • 3
  • 8
  • 14

2 Answers2

2

firstly, i believe that lazy is the default behaviour.
you can test it quite easily-

[TestMethod]
        public void TestLazyLoading()
        {
            Airport firstObject = null;
            using (ISession session = this.SessionFactory.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    ObjectDAO dao = new ObjectDAO(session, CurrentUser);
                    firstObject = dao.GetObject();
                    transaction.Commit();
                }
            }
            Assert.IsFalse(NHibernateUtil.IsInitialized(firstObject.Children));

        }

if you want to specify explicitly lazy / eager, use the following inside your MappingOverride class:

mapping.HasMany(x => x.Employees)
                //.Not
                .LazyLoad()
                ;
J. Ed
  • 6,692
  • 4
  • 39
  • 55
1

To adjust automappings you can use IAutoMappingOverride<SomeEntity>. You can change there exact property that you need

Sly
  • 15,046
  • 12
  • 60
  • 89