/// <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 FriendResidence { Address = "123 Main", City = "Anytown", State = "CA", ZIP = "90210" }; var res2 = new RelativeResidence { Address = "1200 East Street", City = "Big Town", State = "KS", ZIP = "66026" }; var f = new Friend { Name = "Joan Roland", FriendResidence = res1 }; var r = new Relative { Name = "Billy Miner", RelativeResidence = 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 is FriendResidence) { Console.WriteLine("My friend {0} lives at: ", ((FriendResidence)r).Friend.Name); } else if (r is RelativeResidence) { Console.WriteLine("My relative {0} lives at: ", ((RelativeResidence)r).Relative.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); }