Created
May 1, 2019 18:49
-
-
Save kskalski/4ae8a104ea3e846944feb150ae43792d to your computer and use it in GitHub Desktop.
Proto+EF model
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
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