Model as Code (Code First)

Developers often prefer to work with code, and the EF Code First model is a recognition of that fact. Code First allows you to write code that defines your model (tables and relationships). You can then easily work with your model to get data, update it, and save it back to the database.

Code First can be used to target an existing database or generate a database directly from the code model. Of course, you can also use the Visual Studio tools to generate a Code First model based on an existing database.

To write a Code First model in a given project, you start by adding appropriate references to Entity Framework or use the NuGet package manager to install the latest version of EF and add it to your project. Once your ...

Get Microsoft Visual Studio 2015 Unleashed, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.