Skip to content

Instantly share code, notes, and snippets.

@OdeToCode
Created September 18, 2012 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OdeToCode/3744386 to your computer and use it in GitHub Desktop.
Save OdeToCode/3744386 to your computer and use it in GitHub Desktop.
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