1

I was reading about a feature of an ORM called lazy loading, which, it said, means that larger columns are only loaded when the application actually needs them. How would an ORM decide what a "large column" is - would this be, for example, a blob column that can contain a lot of data compared to, say, an unsigned integer column? And when it says it lazy loads the column, does this mean when you run a query, you might not get results for some of the larger columns when you expect to?

4

4 回答 4

3

In NHibernates case, lazy loading is preventing the loading of collection properties on the object (normally by joining another table, or sub selecting) until you access the collection property.

For example, you might want to load all the customers, but if the customers had an orders property (collection of orders), you can load all the customers without the orders, and then lazy load the orders of a specific customer when you want to see the orders.

This saves many database calls when you do not necessarily need all the data up front.

于 2009-07-29T04:06:06.423 回答
1

数据在您访问时获取,而不是在您创建相关的特定对象/集合时获取。

所以像(伪代码):

private void doNothing(int id)
{
    PersistentObject po = BetByID<PersistentObject>(id)
}

实际上从未接触过数据库;然而:

private void doSomething(int id)
{
    PersistenObject po = GetByID<PersistentObject>(id)
    Console.Write(po.id.ToString()) // <- object is fetched here
}
于 2009-07-29T04:15:53.003 回答
0

Yes, a blob column sounds exactly like it. Big VARCHARs, and similar stuff might fall into it as well.

And what it means is that the smaller columns with be cached in memory, but reading the bigger columns will trigger a database read before the value is returned.

Or, at least, that's a likely interpretation of what you are saying. WHICH ORM is it, exactly?

于 2009-07-29T03:59:50.150 回答
-1

常见的方法是用“延迟加载”标记较大的属性。使用 Xml 映射或属性。例如,对于 DataObjects.NET,您应该使用 [Field(LazyLoad = true)] 属性。

于 2009-07-29T07:03:06.457 回答