Extra lazy collections
Sometimes we only need to know the number of items in a collection. It may be for displaying purposes or some behavioral logic. Either way, it seems a bit resource intensive that we should have to load all of the entities from the database, just to count them. With extra lazy collections we can improve this situation a bit.
Getting ready
Refer to the Getting Ready section of this chapter instructions at the beginning of this chapter.
How to do it…
- Add a new folder named
ExtraLazy
to the project. - Add a new class named
Accessory
to the folder, having the code:using NH4CookbookHelpers.Queries.Model; namespace QueryRecipes.ExtraLazy { public class Accessory : Entity { public virtual string Name { get; set; } } }
- Add a new
class
named ...
Get NHibernate 4.x Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.