Skip to content

Instantly share code, notes, and snippets.

@blair55
Last active December 29, 2015 09:19
Show Gist options
  • Select an option

  • Save blair55/7649964 to your computer and use it in GitHub Desktop.

Select an option

Save blair55/7649964 to your computer and use it in GitHub Desktop.
Quick How To: Entity Framework Auto Migrations
// Simple Data Container
public class MyPoco
{
[Key]
public int MyPocoId { get; set; }
public string Status { get; set; }
public DateTime Created { get; set; }
}
// Context used to manage Entities
public class MyDbContext : DbContext
{
public MyDbContext() : base("sql") // connection string name
{}
public DbSet<MyPoco> MyPocos { get; set; }
}
// Persistance class using db context
public class MyPocoPersister
{
public void Save(MyPoco poco)
{
using (var context = new MyDbContext())
{
context.MyPocos.Add(poco);
context.SaveChanges();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment