/// <summary> /// Create a new RelativeResidence object. /// </summary> /// <param name="addressId">Initial value of the AddressId property.</param> /// <param name="address">Initial value of the Address property.</param> /// <param name="city">Initial value of the City property.</param> /// <param name="state">Initial value of the State property.</param> /// <param name="zIP">Initial value of the ZIP property.</param> public static RelativeResidence CreateRelativeResidence(global::System.Int32 addressId, global::System.String address, global::System.String city, global::System.String state, global::System.String zIP) { RelativeResidence relativeResidence = new RelativeResidence(); relativeResidence.AddressId = addressId; relativeResidence.Address = address; relativeResidence.City = city; relativeResidence.State = state; relativeResidence.ZIP = zIP; return(relativeResidence); }
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(); }