It has been a long time since I used Entity Framework on anything other than an brownfield project where most work consisted of adding or removing the occasional field. This series of posts is intented as a refresher as I relearn some concepts.
- Initial Setup
- Seed Data
- Mapping Files
- One-to-many mapping
- Many-to-many mapping
- Many-to-many self mapping
- One-to-one mapping
In a new .Net Framwork class library, add a reference to Microsoft.EntityFramework via the NuGet package manager.
Next add a basic class
Then add a DbContext.
Next add a connection string to the app.config file that was created when you added the NuGet package.
We are now ready to set up migrations. The first step is to enable them. In the Package Manager Console (PMC from now on - this can be found under Tools | NuGet Package Manager | Package Manager Console) run the command to add migrations:
This will create a
/Migrations folder with a file called
Next, create the migration for the person class (this does not need to be named “InitialMigration”)
This will generate a migration script to add the
update-database in the PMC to create the table in your database.