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?
Asked
Active
Viewed 524 times
0
-
Isn't lazy loaded the default? – UpTheCreek Apr 11 '11 at 06:51
-
yes, i believe so. but then, there will be times when we need to on/off lazy loading. – Heinnge Apr 11 '11 at 07:17
2 Answers
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