private List <Vet> SeedVets() { _logger.LogInformation("Seeding Vets"); var radiology = Specialties.First(s => s.Uuid == RadiologyUuid); var surgery = Specialties.First(s => s.Uuid == SurgeryUuid); var dentistry = Specialties.First(s => s.Uuid == DentistryUuid); var vets = new List <Vet> { new Vet { Uuid = Guid.Parse("1de1964d-f3e9-44c1-867f-c664b0a19ef9"), FirstName = "James", LastName = "Carter", }, new Vet { Uuid = Guid.Parse("7514f6d3-6c86-46b9-a689-8cd25cddd51e"), FirstName = "Helen", LastName = "Leary", Specialties = new List <VetSpecialty> { new VetSpecialty { Specialty = radiology, SpecialtyId = radiology.Id } } }, new Vet { Uuid = Guid.Parse("5820115a-1fc6-4d0a-b84a-d10c8cf3fd43"), FirstName = "Linda", LastName = "Douglas", Specialties = new List <VetSpecialty> { new VetSpecialty { Specialty = surgery, SpecialtyId = surgery.Id, }, new VetSpecialty { Specialty = dentistry, SpecialtyId = dentistry.Id } } }, new Vet { Uuid = Guid.Parse("6ec6d4c8-30b7-4e95-830a-46f5f82ee122"), FirstName = "Rafael", LastName = "Ortega", Specialties = new List <VetSpecialty> { new VetSpecialty { Specialty = surgery, SpecialtyId = surgery.Id, } } }, new Vet() { Uuid = Guid.Parse("83456030-cdd4-4ebb-a7ed-30e47d9b3307"), FirstName = "Henry", LastName = "Stevens", Specialties = new List <VetSpecialty> { new VetSpecialty { Specialty = radiology, SpecialtyId = radiology.Id, } } }, new Vet() { Uuid = Guid.Parse("d8428840-577d-4693-9fcb-8ecb9d77e52f"), FirstName = "Sharon", LastName = "Jenkins" } }; var vetUuids = vets.Select(v => v.Uuid); var foundVets = DbContext.Vets .Include(v => v.Specialties) .ThenInclude(s => s.Specialty) .Where(vet => vetUuids.Contains(vet.Uuid)) .ToImmutableList(); var fetchedVets = vets.Select(vet => { var found = foundVets.FirstOrDefault(fv => fv.Uuid == vet.Uuid); return(found ?? vet); }).ToList(); var toInsert = fetchedVets.Where(v => v.Id == 0).ToImmutableList(); if (toInsert.Any()) { _logger.LogInformation($"Will insert {toInsert.Count} vets"); DbContext.AddRange(toInsert); } else { _logger.LogInformation("No vets to insert"); } return(fetchedVets); }