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

Generated properties and default values

From the course: Using Entity Framework Core with Legacy Databases

Start my 1-month free trial

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…

Contents