【发布时间】:2011-01-07 12:58:14
【问题描述】:
我有一个带有子集合价格的类产品:
public class Product
{
private ICollection<Price> prices;
protected Product()
{
prices = new List<Price>();
}
}
NHibernate 映射如下所示
<xml version="1.0" encoding="utf-8">
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Product" table="Product">
<id name="id" column="ProductId" access="field">
<generator class="identity"/>
</id>
<bag name="prices" access="field" cascade="all-delete-orphan" lazy="true">
<key column="ProductId"/>
<one-to-many class="Product.Price"/>
</bag>
</class>
您可以看到价格集合是延迟加载的。
产品是这样从数据库中加载的:
public ICollection<Product> ListProducts()
{
ISession session = GetCurrentSession();
return session
.CreateCriteria(typeof(Product))
.List<Product>();
}
函数引用GetCurrentSession(),内容如下:
protected ISession GetCurrentSession()
{
return sessionProvider.GetCurrentSessionFrom(sessionFactoryConfigName);
}
当我加载产品时,我希望产品中 Price-Collections 的位置是代理,因为价格具有延迟加载 = true。但是在调试时,使用 Visual Studio 监视工具,我可以查看产品并可以查看包含全部内容的价格集合(价格及其所有属性)。为什么会这样?
【问题讨论】:
标签: .net nhibernate lazy-loading