There is such a model:

public class Genre : DbObject { public string GenreName { get; set; } public virtual ICollection<Book> Books { get; set; } = new List<Book>(); public virtual int BooksCount => Books.Count; } 

As far as I understand, every time you access BooksCount will be prompted to the database to calculate the number of objects in the Books collection. Can there be any approach so that the BooksCount property BooksCount overwritten only at the moment of changing the collection or are there any other ways to improve this approach?

  • 2
    and why it is impossible to make a simple get-private set and bind the _booksCount member in it, which is updated when the collection changes? Or are you interested in exactly the calculated property? - Sleeeper
  • @Sleeeper, Yes, in principle, you can, but I would like to know what other options there are. - Lightness
  • 2
    Not at every - but only at the first, if the collection has not been initialized before. - Pavel Mayorov

0