/// <summary> /// Create a new Poem object. /// </summary> /// <param name="poemId">Initial value of the PoemId property.</param> /// <param name="poetId">Initial value of the PoetId property.</param> /// <param name="title">Initial value of the Title property.</param> /// <param name="meterId">Initial value of the MeterId property.</param> public static Poem CreatePoem(global::System.Int32 poemId, global::System.Int32 poetId, global::System.String title, global::System.Int32 meterId) { Poem poem = new Poem(); poem.PoemId = poemId; poem.PoetId = poetId; poem.Title = title; poem.MeterId = meterId; return(poem); }
/// <summary> /// Deprecated Method for adding a new object to the Poems EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToPoems(Poem poem) { base.AddObject("Poems", poem); }
static void RunExample() { using (var context = new EFRecipesEntities()) { var poet = new Poet { FirstName = "John", LastName = "Milton" }; var poem = new Poem { Title = "Paradise Lost" }; var meter = new Meter { MeterName = "Iambic Pentameter" }; poem.Meter = meter; poem.Poet = poet; context.Poems.AddObject(poem); poem = new Poem { Title = "Paradise Regained" }; poem.Meter = meter; poem.Poet = poet; context.Poems.AddObject(poem); poet = new Poet { FirstName = "Lewis", LastName = "Carroll" }; poem = new Poem { Title = "The Hunting of the Shark" }; meter = new Meter { MeterName = "Anapestic Tetrameter" }; poem.Meter = meter; poem.Poet = poet; context.Poems.AddObject(poem); poet = new Poet { FirstName = "Lord", LastName = "Byron" }; poem = new Poem { Title = "Don Juan" }; poem.Meter = meter; poem.Poet = poet; context.Poems.AddObject(poem); context.SaveChanges(); } using (var context = new EFRecipesEntities()) { context.ContextOptions.LazyLoadingEnabled = true; var poets = from p in context.Poets select p; foreach (var poet in poets) { Console.WriteLine("{0} {1}", poet.FirstName, poet.LastName); foreach (var poem in poet.Poems) { Console.WriteLine("\t{0} ({1})", poem.Title, poem.Meter.MeterName); } } } // using our vwLibrary view using (var context = new EFRecipesEntities()) { var items = from i in context.vwLibraries select i; foreach (var item in items) { Console.WriteLine("{0} {1}", item.FirstName, item.LastName); Console.WriteLine("\t{0} ({1})", item.Title, item.MeterName); } } Console.WriteLine("Press <enter> to continue..."); Console.ReadLine(); }