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?
相关问题
- NOT DISTINCT query in mySQL
- Flush single app django 1.9
- keeping one connection to DB or opening closing pe
- Tell hibernate hbm2ddl not create individual table
- Mysql-installer showing error : Memoy could not be
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?
Common approach is to mark larger properties with "lazy load". Using Xml mapping or attributes. E.g. For DataObjects.NET you should use [Field(LazyLoad = true)] property attribute.
The data gets fetched when you access it, not when you create the particular object/collection in question.
so something like (pseudocode):
doesn't actually touch the db ever; whereas:
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.