/// <summary> /// Create a new Residence 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 Residence CreateResidence(global::System.Int32 addressId, global::System.String address, global::System.String city, global::System.String state, global::System.String zip) { Residence residence = new Residence(); residence.AddressId = addressId; residence.Address = address; residence.City = city; residence.State = state; residence.Zip = zip; return(residence); }
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 Residences EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToResidences(Residence residence) { base.AddObject("Residences", residence); }