public void SelectExistingFromTableWithUserGeneratedGuidAsPrimaryKey() { using (var db = new UserGeneratedTeamContext()) { var teams = new List <Team>(); // Add ten teams to the database (Team 0 - Team 9) for (int i = 0; i < 10; i++) { teams.Add(new Team { Id = Guid.NewGuid(), Name = $"Team #{i}" }); } // Save the ten first teams to the database. db.BulkInsertAll(new BulkInsertRequest <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 Team { Id = Guid.NewGuid(), Name = $"Team #{i}" }); } // The only teams we should get back out of the 20 teams (Team 0 - Team 19) // are the first ten that we saved to the database. var existingTeams = db.BulkSelectExisting <Team, Team>(new BulkSelectRequest <Team>(new[] { "Id" }, teams)); existingTeams = existingTeams.OrderBy(t => t.Name).ToList(); Assert.AreEqual(10, existingTeams.Count); for (int i = 0; i < 10; i++) { Assert.AreEqual(teams[i].Id, existingTeams[i].Id); Assert.AreEqual(teams[i].Name, existingTeams[i].Name); } } }
public void SelectExistingFromTableWithUserGeneratedGuidAsPrimaryKeyShouldWork() { using (var db = new UserGeneratedTeamContext()) { var teams = new List <Team>(); for (int i = 0; i < 10; i++) { teams.Add(new Team { Id = Guid.NewGuid(), Name = $"Team #{i}" }); } teams = teams.OrderBy(t => t.Name).ToList(); db.BulkInsertAll(new BulkInsertRequest <Team> { Entities = teams, SortUsingClusteredIndex = false }); for (int i = 10; i < 20; i++) { teams.Add(new Team { Id = Guid.NewGuid(), Name = $"Team #{i}" }); } var existingTeams = db.BulkSelectExisting <Team, Team>(new BulkSelectRequest <Team>(new [] { "Id" }, teams)); existingTeams = existingTeams.OrderBy(t => t.Name).ToList(); Assert.AreEqual(10, existingTeams.Count); for (int i = 0; i < 10; i++) { Assert.AreEqual(teams[i].Id, existingTeams[i].Id); Assert.AreEqual(teams[i].Name, existingTeams[i].Name); } } }