Last active
December 29, 2015 09:19
-
-
Save blair55/7649964 to your computer and use it in GitHub Desktop.
Quick How To: Entity Framework Auto Migrations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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