Ejemplo n.º 1
0
        //データ追加
        private static void AddData()
        {
            using (var manager = new BookManager())
            {
                var p1 = new Publisher
                {
                    Name = "テスト1",
                    Address = "神奈川県・・・"
                };

                manager.Publishers.Add(p1);
                manager.Publishers.Add(new Publisher
                {
                    Name = "test2",
                    Address = "東京都・・・"
                });

                manager.Books.Add(new Book
                {
                    Title = "Entity Framework CTP4",
                    Publisher = p1
                });

                manager.Books.Add(new Book
                {
                    Title = "MySQL",
                    Publisher = p1
                });

                manager.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        //データ追加
        private static void AddData()
        {
            using (var manager = new BookManager())
            {
                var p1 = new Publisher
                {
                    Name    = "テスト1",
                    Address = "神奈川県・・・"
                };

                manager.Publishers.Add(p1);
                manager.Publishers.Add(new Publisher
                {
                    Name    = "test2",
                    Address = "東京都・・・"
                });

                manager.Books.Add(new Book
                {
                    Title     = "Entity Framework CTP4",
                    Publisher = p1
                });

                manager.Books.Add(new Book
                {
                    Title     = "MySQL",
                    Publisher = p1
                });

                manager.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        //データ検索
        private static void SelectData()
        {
            using (var manager = new BookManager())
            {
                //Include で Books の内容をロードするように指定
                //Include が無いと Books プロパティの値が null になる
                var res = from p in manager.Publishers.Include("Books")
                          where p.Books.Count > 0
                          select p;

                res.ToList().ForEach(p =>
                {
                    Console.WriteLine("publisher: {0}", p.Name);
                    p.Books.ToList().ForEach(b => Console.WriteLine("book: {0}", b.Title));
                    Console.WriteLine();
                });
            }
        }
Ejemplo n.º 4
0
        //データ検索
        private static void SelectData()
        {
            using (var manager = new BookManager())
            {
                //Include で Books の内容をロードするように指定
                //Include が無いと Books プロパティの値が null になる
                var res = from p in manager.Publishers.Include("Books")
                          where p.Books.Count > 0
                          select p;

                res.ToList().ForEach(p =>
                {
                    Console.WriteLine("publisher: {0}", p.Name);
                    p.Books.ToList().ForEach(b => Console.WriteLine("book: {0}", b.Title));
                    Console.WriteLine();
                });
            }
        }