Esempio n. 1
0
        public void LINQTestJoin4()
        {
            var lowNums = from player in context.HOCKEY
                          join p in context.HOCKEY on player.NUMBER equals p.NUMBER + 1 into NextPlayer
                          from p2 in NextPlayer.DefaultIfEmpty()
                          orderby player.NUMBER
                          select new
            {
                Team             = player.TEAM,
                Player           = player.NAME,
                PlayerNumber     = player.NUMBER,
                NextPlayer       = p2 == null ? "<none>" : p2.NAME,
                NextPlayerNumber = p2 == null ? -1 : p2.NUMBER
            };

            int count = 0;

            Console.WriteLine("Each player with the player having the previous number:");
            foreach (var x in lowNums)
            {
                Console.WriteLine(x.Team + " " + x.Player + " (" + x.PlayerNumber + ") " + x.NextPlayer + " (" + x.NextPlayerNumber + ")");
                if (x.NextPlayerNumber != -1)
                {
                    Assert.AreEqual(x.PlayerNumber, x.NextPlayerNumber + 1);
                }
                count++;
            }
            Assert.AreEqual(tableRows, count);
        }
Esempio n. 2
0
        public void LINQTestJoin4()
        {
            using (var context = new EFCodeFirstContext())
            {
                var lowNums = from player in context.Hockey
                              join p in context.Hockey on player.Number equals p.Number + 1 into NextPlayer
                              from p2 in NextPlayer.DefaultIfEmpty()
                              orderby player.Number
                              select new
                {
                    Team             = player.Team,
                    Player           = player.Name,
                    PlayerNumber     = player.Number,
                    NextPlayer       = p2 == null ? "<none>" : p2.Name,
                    NextPlayerNumber = p2 == null ? -1 : p2.Number
                };

                int count = 0;
                Console.WriteLine("Each player with the player having the previous number:");
                foreach (var x in lowNums)
                {
                    Console.WriteLine(x.Team + " " + x.Player + " (" + x.PlayerNumber + ") " + x.NextPlayer + " (" + x.NextPlayerNumber + ")");
                    if (x.NextPlayerNumber != -1)
                    {
                        Assert.AreEqual(x.PlayerNumber, x.NextPlayerNumber + 1);
                    }
                    count++;
                }
                Assert.AreEqual(tableRows, count);
            }
        }