From the course: Using Entity Framework Core with Legacy Databases
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Generated properties and default values
From the course: Using Entity Framework Core with Legacy Databases
Generated properties and default values
- [Narrator] Value generation is an integral part of many databases. For non-nullable fields a default value can prevent the need to require a value when a new row is added. It's also common for row ID's and things like update dates. Let's illustrate value generation with entity framework by adding a new order to our database. We'll start in the main method of our program. We can remove our sales person list from earlier. Let's get a customer. A sales person. And an item that was ordered. Since we're not particular about which one for this illustration we're just gonna grab the first one from the database for each of these. Now, we'll create a new order end code. We'll set the customer. Sales person. And item from above. Since order item is a list we'll create an empty list for that. And add a new order item for our product. We'll set the order date to right now. Now that we have an order we can add it to the context orders collection. We've made the change to our entity framework…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Why change the generated model2m 8s
-
(Locked)
Changing names1m 49s
-
(Locked)
Using shadow properties2m 23s
-
(Locked)
Generated properties and default values4m 34s
-
(Locked)
Using backing fields3m 35s
-
(Locked)
Adding and altering indexes3m 38s
-
(Locked)
Adding concurrency tokens and timestamps4m 8s
-
(Locked)
-
-
-