CS295N Web Development 1: ASP.NET

Seed Data and LINQ

 

Weekly Topics 
1. Intro to Web Dev6. Unit Testing
2. Intro to MVC & Deploying to Azure7. Database & Entity Framework
3. Working with Data8. Unit Testing & The Repository Pattern
4. Bootstrap9. Linq & Seed Data
5. Midterm Quiz & Term Project Proposal10. Debugging

 

Contents

Announcements

For 11/22/23

 

Introduction

Seed data is data that is automatically added to your database when the application is started. There are two main purposes for seed data:

Seeding Your Database

One way to seed your database is to write a class with a static method that will add entities to the database. The method to seed the database will be called from Startup. I put mine in a static class named SeedData, but it's not a special name (not part of a convention).

Note that the method I'm using here is different from the method shown in the textbook (Murach and Delameter, Ch. 4, pg 142, 2022).

Seed Data class and method

Call the Seed method from Program.cs

The Seed method will get called when you run your web app.

 

Language Integrated Query (LINQ)

Example

Walk through the Planet example.

Exercise

Add to the Planet example:

 

 

References

 


Creative Commons License ASP.NET Core MVC Lecture Notes by Brian Bird is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.