public IEnumerable <string> Run() { _context = new FamilyMembersWithFluentConfiguration(); var kidsWhosNamesBeginWithC = from d in _context.Dads from k in d.Kids where k.Name.StartsWith("C") select k.Name; Log("There are {0} kids whose names begin with 'C' ({1})", kidsWhosNamesBeginWithC.Count(), String.Join(",", kidsWhosNamesBeginWithC)); var kidsWhoAreAlsoDads = from d in _context.Dads join k in _context.Kids on d.FirstName equals k.Name select d.FirstName; Log("There are {0} kids who are dads ({1})", kidsWhoAreAlsoDads.Count(), String.Join(",", kidsWhoAreAlsoDads)); Log("Inefficient count of kids per dad"); foreach (var dad in _context.Dads) { Log("{0} has {1} kids", dad.FirstName, dad.Kids.Count); } Log("Efficient count of kids per dad"); foreach (var dad in _context.Dads.Include(x => x.Kids)) { Log("{0} has {1} kids", dad.FirstName, dad.Kids.Count); } _context.SaveChanges(); return(Enumerable.Empty <string>()); }
public IEnumerable <string> Run() { Database.SetInitializer(new OrtmanFamilyInitializer()); var context = new FamilyMembersWithFluentConfiguration(); var charles = new Dad() { FirstName = "Charles", Address = new Address() }; context.Dads.Add(charles); context.Messages.Add(new Message("Inserted dad [charles] without setting a birthday")); context.SaveChanges(); return(Enumerable.Empty <string>()); }
public IEnumerable <string> Run() { Database.SetInitializer(new OrtmanFamilyInitializer()); var context = new FamilyMembersWithFluentConfiguration(); //since i know i've only just created 1 dad, i just hardcode the ID var chris = context.Dads.First(x => x.FirstName == "Chris"); var clara = new Kid() { Name = "Clara", Birthday = DateTime.Parse("1/21/2009") }; chris.Kids.Add(clara); var message = new Message("Data inserted via conventions demo"); context.Messages.Add(message); context.SaveChanges(); return(Enumerable.Empty <string>()); }