I have a list of a person object that i want to insert in the database, but first i need to know if every person of the list already exists in the database or not. (I'm not using any ORM like EntityFramework,
just ADO.NET of Oracle provider)

For example:

```
var listOfPersons = new List<Person>(); //this list could have 100 of person objects

//I need to check if every person of a list already exists in the database
foreach(var person in listOfPersons)
{
   //Here we made the call to the database for every person.
   //We make the query in the database to a table that could have millions of records        
   var existInDb = db.ExistPersonInDb(person.DocumentId); 

   //If not exists insert in the database
}

```

I need to know if this approach is the best way or not, because in this example i'll open/close the connection for every person in the list and then go to query the database to a table that could have a millions of records.

Or i could call the database just once and bring the millions of records of the table and assign it to a list.

Like this:

```
var personsInDb = db.getPersonsInDb().ToList(); //Get all the persons from database and add it to a list

var listOfPersons = new List<Person>(); //this list could have 100 of person objects

//I need to check if every person of a list already exists in the database
 foreach(var person in listOfPersons)
 {  
    //And here with Linq just check if the person that i want to insert already exists in the personsInDb list     
    var existInDb = personsInDb.Exists(p => p.DocumentId== person.DocumentId); 

    //If not exists insert in the database
 }

```

Of this two example what is the best way to solve this problem that i have? Or if you have another solution please let me know.