/// <summary> /// Create a new Relative object. /// </summary> /// <param name="personId">Initial value of the PersonId property.</param> /// <param name="name">Initial value of the Name property.</param> public static Relative CreateRelative(global::System.Int32 personId, global::System.String name) { Relative relative = new Relative(); relative.PersonId = personId; relative.Name = name; return(relative); }
static void RunExample() { using (var context = new EFRecipesEntities()) { var res1 = new Residence { Address = "123 Main", City = "Anytown", State = "CA", Zip = "90210" }; var res2 = new Residence { Address = "1200 East Street", City = "Big Town", State = "KS", Zip = "66026" }; var f = new Friend { Name = "Joan Roland" }; f.Residences.Add(res1); var r = new Relative { Name = "Billy Miner" }; r.Residences.Add(res2); context.Friends.AddObject(f); context.Relatives.AddObject(r); context.SaveChanges(); } using (var context = new EFRecipesEntities()) { context.ContextOptions.LazyLoadingEnabled = true; foreach (var r in context.Residences) { if (r.Friends != null) { Console.WriteLine("My friend {0} lives at: ", r.Friends.Name); } else if (r.Relatives != null) { Console.WriteLine("My relative {0} lives at: ", r.Relatives.Name); } Console.WriteLine("\t{0}", r.Address); Console.WriteLine("\t{0}, {1} {2}", r.City, r.State, r.Zip); } } Console.WriteLine("Press <enter> to continue..."); Console.ReadLine(); }
/// <summary> /// Deprecated Method for adding a new object to the Relatives EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToRelatives(Relative relative) { base.AddObject("Relatives", relative); }