コード例 #1
0
        static void Main(string[] args)
        {
            var context = new ScifiContext();
            //var authors = context.Authors;

            //foreach (var author in authors)
            //{
            //    Console.WriteLine(author);
            //}

            //Console.WriteLine(authors.Count());

            //var andyWeir = new Author
            //{
            //    Name = "Andy Weir",
            //    BirthDate = new DateTime(1968, 7, 7)
            //};

            //Console.WriteLine(andyWeir);
            //context.Authors.Add(andyWeir);
            //context.SaveChanges();
            //Console.WriteLine(andyWeir);

            //var marsNovels = context.Novels
            //    .Where(n => n.Title.Contains("Mars"));


            //var ksrMarsNovels = marsNovels
            //    .Where(n => n.AuthorID == 274);

            //foreach (var novel in ksrMarsNovels)
            //{
            //    Console.WriteLine(novel);
            //}

            //Console.WriteLine(ksrMarsNovels.Count());


            var ksr = context.Authors.Single(a => a.ID == 274);

            //Console.WriteLine(ksr.GetType().FullName);

            Console.WriteLine(ksr);
            foreach (var novel in ksr.Novels)
            {
                Console.WriteLine($"  {novel}");
            }

            //var authors = context.Authors.Include("Novels");

            //foreach (var author in authors)
            //{
            //    //Console.WriteLine(author.Novels.Count());
            //    Console.WriteLine($"{author.Name} ({author.Novels.Count()})");
            //}
        }
コード例 #2
0
        static void Main(string[] args)
        {
            //ConsoleProfiling.Start();

            //Console.WriteLine("Starting to call methods..");

            //using (StackExchange.Profiling.MiniProfiler.Current.Step("Call Methods"))
            //{
            var context = new ScifiContext();

            foreach (var author in context.Authors.Include("Novels"))
            {
                Console.WriteLine($"{author.Name} - {author.Novels.Count()} novels");
            }

            //var heinlein = context.Authors.Include("Novels").Single(a => a.ID == 92);

            //Console.WriteLine(heinlein);
            //foreach (var novel in heinlein.Novels)
            //{
            //    Console.WriteLine($"    {novel}");
            //}
            //}

            // //Stop profiling and show results
            //Console.WriteLine(ConsoleProfiling.StopAndGetConsoleFriendlyOutputStringWithSqlTimings());


            //foreach (var author in context.Authors)
            //{
            //    Console.WriteLine(author);
            //}

            //var cline = new Author
            //{
            //    Name = "Ernest Cline",
            //    BirthDate = new DateTime(1981, 8, 9)
            //};

            //Console.WriteLine(cline);

            //context.Authors.Add(cline);
            //context.SaveChanges();

            //Console.WriteLine(cline);

            //foreach (var novel in context.Novels)
            //{
            //    Console.WriteLine(novel);
            //}
        }
コード例 #3
0
        public ActionResult Index()
        {
            var context = new ScifiContext();

            var heinlein = context.Authors.Single(a => a.ID == 92);

            Console.WriteLine(heinlein);
            foreach (var novel in heinlein.Novels)
            {
                Console.WriteLine($"    {novel}");
            }

            return(View());
        }