This course will be retired on June 1, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Let's make a simple change to our ComicBook entity class and see how EF handles updates to our model.
Follow Along
To follow along commiting your changes to this course, you'll need to fork the dotnet-comic-book-gallery-model repo. Then you can clone, commit, and push your changes to your fork like this:
git clone <your-fork>
cd dotnet-comic-book-gallery-model
git checkout tags/v2.4 -b controlling-database-generation
Storing Calculated Values
The ComicBook AverageRating
column is storing a calculated value. Our system doesn't store ratings, so we're assuming (or imagining) that there'll be an automated, scheduled process that will calculate the rating for each comic book and update the records in our database.
Storing calculated data has tradeoffs. On the upside, it's quick to retrieve a value as it doesn't need to be calculated. On the downside, there's a risk that the calculated value will be "stale", meaning that the stored calculated value might not represent the current state of the source data. The likelihood of this happening is directly related to how often the calculated value is generated or refreshed from the source data.
We went with the approach of storing a calculated value in order to keep our code base as simple as possible so that we could keep the focus on learning Entity Framework. In a real-life project, the AverageRating
value would probably be calculated every time that it was requested, though ultimately, our approach would be guided and informed by the overall performance of the system.
Additional Learning
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up