code-first

Using Code-First Migrations in Entity Framework

Entity Framework Code-First includes a new feature for maintaining database changes in code files: Migrations. Migrations are code files that describe what changes were made to the database schema at different points in time. You create the migrations when you need them, and the code will use those files (and a corresponding table in the target database) to keep the schema changes in sync with what the code expects. In other words, you can manage your database schema without ever... Read more >

Building a Code-First Model Using FluentAPI in Entity Framework

Now that we've created a Code-First model using Attributes, let's walk through the other manner by which we can create a model: FluentAPI. The Model Once again, we will be using the same CourseCatalog model: To start off, let's create the classes necessary to represent these entities: public class Student { public int ID { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public DateTime DateOfBirth { get; set; } public virtual StudentAddress Address { get; set; } public virtual ICollection<... Read more >

Building a Code-First Model Using Attributes in Entity Framework

In previous posts we have created a database-first model, created a model-first model using an EDMX, and created a code-first model from an existing database. In this post, we will create a code-first model from scratch using DataAnnotations; in a later post we will create the same model using FluentAPI, and in another post we will demonstrate how to manage changes to your database schema using Code-First Migrations. For now, let's build a code first model using attributes! Creating the... Read more >

Creating a Code-First Model from a Database in Entity Framework

In previous posts we've explored creating a database-first model and creating a model-first model. Both of those designs used the same thing: an EDMX file. In order to use that file, we had to use a designer. But what if we don't want to bother with a designer? Maybe we'd rather just work with code. Well, good, because that's what we're going to do in this post. We're going to return to the Northwind database and use it to create... Read more >