Created
September 18, 2012 17:14
-
-
Save OdeToCode/3744386 to your computer and use it in GitHub Desktop.
This file contains 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
using System; | |
using System.Linq; | |
using System.Data.Entity; | |
namespace TestEF | |
{ | |
public class Thing | |
{ | |
public int Id { | |
get; | |
set; | |
} | |
public string Name { | |
get; | |
set; | |
} | |
} | |
public class ThingDb : DbContext | |
{ | |
public ThingDb () | |
:base("name=ThingDB") | |
{ | |
} | |
public DbSet<Thing> Things { | |
get; | |
set; | |
} | |
} | |
class MainClass | |
{ | |
public static void Main (string[] args) | |
{ | |
using (var db = new ThingDb()) { | |
db.Things.Add (new Thing { Name="Foo" }); | |
db.SaveChanges (); | |
} | |
using (var db = new ThingDb()) { | |
var things = db.Things.ToList(); | |
foreach (var item in things) { | |
Console.WriteLine (item.Name); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment