If I set LazyLoad on multiple properties-columns with NHiberante and access those properties one after the other, would it query the database for each property?
Example:
public class Product
{
public virtual int ID {get; set;}
public virtual string Name {get; set;}
public virtual string FullName {get; set;}
public virtual float Price {get; set;}
}
public class ProductMap : ClassMap<Product>
{
Id(p => p.ID);
Map(p => p.Name).Not.LazyLoad();
Map(p => p.FullName).LazyLoad(); // Redundant - I know...
Map(p => p.Price).LazyLoad(); // Redundant - I know...
}
if I query the DB like this:
var product = session.Load<Prodct>(2);
if (product.FullName == "*" && product.Price = 111)
Will there be 3 queries
- The Product entity
- The FullName property
- The Price property
or when NHibernate query the DB for FullName it will query all the columns of the row?
NHibernate will load all the lazy properties of an entity in a single query (you can try for yourself…)
The main use case for this feature is blobs.
Lazy references, on the other hand, are loaded as needed.
As a side note,
session.Loaddoes not query the DB; it just creates a proxy, which will be loaded lazily. Usesession.Get.