Skip to content

Instantly share code, notes, and snippets.

@kskalski
Created May 1, 2019 18:49
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 kskalski/4ae8a104ea3e846944feb150ae43792d to your computer and use it in GitHub Desktop.
Save kskalski/4ae8a104ea3e846944feb150ae43792d to your computer and use it in GitHub Desktop.
Proto+EF model
using (var db = new Database()) {
db.Fruits.Add(new Models.Fruit { Name = "Apple", Weight = 345.2 });
var tree = new Models.Tree { Height = 45 };
tree.Fruits.Add(new Models.Fruit { Name = "Banana", Weight = 25.1 });
db.Trees.Add(tree);
var count = db.SaveChanges();
Console.WriteLine("{0} records saved to database", count);
}
using (var db = new Database()) {
Console.WriteLine("All fruits in database:");
foreach (var fruit in db.Fruits) {
Console.WriteLine(" - {0}", fruit);
}
Console.WriteLine("garden is {0}", db.Trees.Include(t => t.Fruits).First());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment