I'm trying to query contacts based on their e-mail value using xConnect, but my query doesn't return any results:
var queryable = client.Contacts
.Where(c => c.GetFacet<EmailAddressList>(EmailAddressList.DefaultFacetKey).PreferredEmail.SmtpAddress == email)
.WithExpandOptions(new ContactExpandOptions(PersonalInformation.DefaultFacetKey, EmailAddressList.DefaultFacetKey));
var enumerator = queryable.GetBatchEnumeratorSync(50);
However, when I just check if the SmtpAddress
isn't empty, it does return results. The only downside is that I then have to search through all those contacts after retrieving them in-memory which is, let's say, kind of a performace hog (my local SQL Server instance is still churning away as I'm typing this):
var queryable = client.Contacts
.Where(c => c.GetFacet<EmailAddressList>(EmailAddressList.DefaultFacetKey).PreferredEmail.SmtpAddress != string.empty)
.WithExpandOptions(new ContactExpandOptions(PersonalInformation.DefaultFacetKey, EmailAddressList.DefaultFacetKey));
var enumerator = queryable.GetBatchEnumeratorSync(50);
while (enumerator.MoveNext())
{
foreach (var contact in enumerator.Current.Where(c => c.GetFacet<EmailAddressList>(EmailAddressList.DefaultFacetKey).PreferredEmail.SmtpAddress == email))
{...}
}
The e-mail address I'm looking for is definitely in the set of contacts as I can find it just fine with the second method, retrieving all contacts with a non-empty e-mail address and using the .Where()
line from the first method when iterating on the batch result.
So what's the difference here, why can't I search for a string ìn the query?