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.
Refer to the Getting Ready section of this chapter instructions at the beginning of this chapter.
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
namedCar
to the folder:using System; using System.Collections.Generic; namespace QueryRecipes.ExtraLazy { public class Car { public Car() { Accessories=new HashSet<Accessory>(); ...