EF Code-First is a new flavour in the Entity Framework 4.0. Ice Cream Bar. Instead of creating a model (model-first) or reverse engineering a database (database-first) you just start writing code, isn’t that sweet?
Actually it’s quite simple and straight forward:
Your entities are pure POCO classes, no need to derive from a base class or implement any interfaces.
Navigation properties can be defined by using the ICollection<T> interface.
public class FAQCategory
{
public int Id { get; set; }
public string Description { get; set; }
public virtual ICollection<FAQItem> FAQItems { get; set; }
}
A context can be created by deriving from the DbContext class:
public class CustomContext : DbContext
{
public DbSet<FAQCategory> FAQCategories { get; set; }
public DbSet<FAQItem> FAQItems { get; set; }
}
In EF Code-First there is no visual model (.edmx), all we have is code
EF Code-First can create the database for you, or you can map to an existing database.
Validation is supported by using Data annotation attributes.
To download EF Code-First (CTP-5) click here. For more details: read Scott Guthrie BLOG