Exemple #1
0
        static void Related()
        {
            var db = new MusicDbContext();

            var results = db.Bands
                          .Include(b => b.Albums)
                          .ToListAsync().Result;

            foreach (var band in results)
            {
                System.Console.WriteLine(band.Name);
                foreach (var album in band.Albums)
                {
                    System.Console.WriteLine("    " + album.Title);
                }

                System.Console.WriteLine();
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var db = new MusicDbContext();

            var result = db.Bands
                         .Include(b => b.Albums)
                         .SingleAsync(b => b.Id == 2)
                         .Result;

            result.Name = "Pearl Jam 2";

            result.Albums.Add(new Album()
            {
                Title = "Vs.",
                Year  = 1993,
                Style = MusicStyle.Grunge
            });

            db.SaveChanges();
        }
Exemple #3
0
        static void Insert()
        {
            var db      = new MusicDbContext();
            var newBand = new Band();

            newBand.Name = "Pearl Jam";

            var newAlbum = new Album();

            newAlbum.Title = "Ten";
            newAlbum.Year  = 1991;
            newAlbum.Style = MusicStyle.Grunge;

            newBand.Albums = new List <Album>();
            newBand.Albums.Add(newAlbum);

            db.Bands.Add(newBand);


            db.SaveChanges();

            System.Console.WriteLine("Presione cualquier tecla...");
            Console.ReadLine();
        }