Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 需要解释NHibernation延迟加载吗_.net_Nhibernate_Lazy Loading - Fatal编程技术网

.net 需要解释NHibernation延迟加载吗

.net 需要解释NHibernation延迟加载吗,.net,nhibernate,lazy-loading,.net,Nhibernate,Lazy Loading,我有一款儿童系列产品,价格如下: public class Product { private ICollection<Price> prices; protected Product() { prices = new List<Price>(); } } 当我加载产品时,我希望产品中价格集合的位置是一个代理,因为价格具有lazy load=true。但在调试过程中,使用VisualStudioWatch工具,我可以查看

我有一款儿童系列产品,价格如下:

public class Product
{
    private ICollection<Price> prices;

    protected Product()
    {
        prices = new List<Price>();
    }
}

当我加载产品时,我希望产品中价格集合的位置是一个代理,因为价格具有lazy load=true。但在调试过程中,使用VisualStudioWatch工具,我可以查看产品,并可以查看包含完整内容的prices集合以及它们的所有属性。为什么会这样?

由于您在调试时访问了Prices属性,代理将加载products集合。。。 这意味着,您通过“监视”Prices属性触发了延迟加载过程


通过配置nhibernate,您可以看到所执行的SQL语句将显示为SQL配置选项。由于您在调试时访问了Prices属性,代理将加载products集合。。。 这意味着,您通过“监视”Prices属性触发了延迟加载过程


通过配置nhibernate,您可以看到所执行的SQL语句将显示SQL配置选项。

因为VS总是触发价格的getter方法,如果价格为空,则会加载所有价格。
如果您使用的是SQL Server,并且希望检查延迟加载是否按预期工作,请使用SQL Server Profiler。如果您使用的是Express edition,请使用AnjLab SqlProfiler。

,因为VS总是触发价格的getter方法,如果价格为空,则反过来加载所有价格。
如果您使用的是SQL Server,并且希望检查延迟加载是否按预期工作,请使用SQL Server探查器。如果您使用的是Express edition,请使用AnjLab SqlProfiler。

或使用Nhiberante在log4net中记录的SQL语句,或使用Nhiberante在log4net中记录的SQL语句
<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>();
    }
protected ISession GetCurrentSession()
    {
         return sessionProvider.GetCurrentSessionFrom(sessionFactoryConfigName);
    }