My first thougth was to create a dynamic query like this:
Select Id, Name
From Object__c
Where ((field1__c = '1' AND field2__c = '2') OR (field1__c = '3' AND field2__c = '4') OR ... )
The code needed for that can look like the following:
String query = 'Select Id From Object__c Where (';
Integer counter = 1;
for(pair p : pairs){
query += '(field1__c = \'' + p.x + '\' AND field2__c = ' + p.y + ') ';
if(counter < pairs.size())
query+= ' OR ';
counter++;
}
query += ')';
The other way to do such queries (and I think it is an eleganter way) is to create a new formula field that concatenates two fields into the one sting and then just bind a list variable in the dynamic SOQL query.
Formula field generates a sing like this:
field1__c + '/' + field2__c
The apex code for the query generation:
list<string> str = new list<string>();
for(pair p : pairs){
str.add(p.x + '/' + String.valueOf(p.y));
}
String query = 'Select Id From Object__c Where MyFormula__c = : str ';
List<Object__c> obj = Database.query(query);