public void SelectNotExistingFromTableWithDbGeneratedGuidAsPrimaryKeyShouldWork()
        {
            using (var db = new DbGeneratedTeamContext())
            {
                var teams = new List <DM.Teams.UsingDbGeneratedGuidKeys.Team>();
                for (int i = 0; i < 10; i++)
                {
                    teams.Add(new DM.Teams.UsingDbGeneratedGuidKeys.Team {
                        Name = $"Team #{i}"
                    });
                }

                db.BulkInsertAll(new BulkInsertRequest <DM.Teams.UsingDbGeneratedGuidKeys.Team>
                {
                    Entities = teams
                });

                for (int i = 10; i < 20; i++)
                {
                    teams.Add(new DM.Teams.UsingDbGeneratedGuidKeys.Team {
                        Name = $"Team #{i}"
                    });
                }

                var existingTeams = db.BulkSelectNotExisting <DM.Teams.UsingDbGeneratedGuidKeys.Team, DM.Teams.UsingDbGeneratedGuidKeys.Team>(new BulkSelectRequest <DM.Teams.UsingDbGeneratedGuidKeys.Team>(new [] { "Id" }, teams));
                Assert.AreEqual(10, existingTeams.Count);
                for (int i = 0; i < 10; i++)
                {
                    Assert.AreEqual(teams[i + 10].Id, existingTeams[i].Id);
                    Assert.AreEqual(teams[i + 10].Name, existingTeams[i].Name);
                }
            }
        }
Beispiel #2
0
        public void SelectNotExistingFromTableWithDbGeneratedGuidAsPrimaryKeyShouldWork()
        {
            using (var db = new DbGeneratedTeamContext())
            {
                var teams = new List <DM.Teams.UsingDbGeneratedGuidKeys.Team>();

                // Add ten teams to the database (Team 0 - Team 9)
                for (int i = 0; i < 10; i++)
                {
                    teams.Add(new DM.Teams.UsingDbGeneratedGuidKeys.Team {
                        Name = $"Team #{i}"
                    });
                }

                // Save the ten first teams to the database.
                db.BulkInsertAll(new BulkInsertRequest <DM.Teams.UsingDbGeneratedGuidKeys.Team>
                {
                    Entities = teams
                });

                // Add another ten teams (Team 10 - Team 19) to
                // the list but not to the database.
                for (int i = 10; i < 20; i++)
                {
                    teams.Add(new DM.Teams.UsingDbGeneratedGuidKeys.Team {
                        Name = $"Team #{i}"
                    });
                }

                // The only teams we should get back out of the 20 teams (Team 0 - Team 19)
                // are the last ten that we did not save to the database.
                var existingTeams = db.BulkSelectNotExisting <DM.Teams.UsingDbGeneratedGuidKeys.Team, DM.Teams.UsingDbGeneratedGuidKeys.Team>(new BulkSelectRequest <DM.Teams.UsingDbGeneratedGuidKeys.Team>(new[] { "Id" }, teams));
                Assert.AreEqual(10, existingTeams.Count);
                for (int i = 0; i < 10; i++)
                {
                    Assert.AreEqual(teams[i + 10].Id, existingTeams[i].Id);
                    Assert.AreEqual(teams[i + 10].Name, existingTeams[i].Name);
                }
            }
        }