Join Richard Goforth for an in-depth discussion in this video Using backing fields, part of Accessing Existing Databases with Entity Framework Core.
- [Narrator] Sometimes it makes sense to have…a public property on the data model perform logic…in the setter.…Maybe you want to use a specific value…when the property is set to null…or want to do some validation…based on the other properties in your model.…It can even be that the property doesn't have a setter…because the value is Read Only in your application.…It's likely that you don't want to run this logic…when Entity Framework is populating…the model from the database.…We can have Entity Framework populate…the backing fields directly rather than using…the public properties.…
Let's add some logic to the email setter of Customer…and see this in action.…First, we'll add a backing field for our public property.…Now, we'll change the getter to return that backing field…and we'll change the setter to do our logic.…In this case, we'd like to make sure new emails entered…are in all lowercase.…Now, if Entity Framework doesn't know…about this backing field, the logic in the setter…will be runned whenever populating the model…
- Setting up your project
- Connecting to a legacy database
- Scaffolding an initial model and context
- Improving the model
- Updating properties and indexes
- Adding concurrency tokens and timestamps
- Creating complex relationships
- Working with non-Microsoft databases such as SQLite and PostgreSQL
Skill Level Intermediate
SQL Server 2014 Essential Trainingwith Martin Guidry3h 51m Intermediate
Microsoft SQL Server 2014: Backup and Recoverywith Martin Guidry1h 22m Intermediate
1. Get Started with EF Core: On Your Legacy Database
2. Improve the Model
3. Model Complex Relationships
4. Work with Non-Microsoft Databases
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.