1. Work with search

Supported methods and operators for xConnect search

Version:

xConnect search does not implement all of IAsyncQueryable<T> methods and throws a Sitecore.XConnect.Search.YourLinqIsTooStrongException or an XdbModelException exception if you try to use a method that is not supported. The following table applies to both contact and interaction searches unless explicitly stated.

Refer to the xConnect Client API for an overview of synchronous and asynchronous extension methods.

Extension method and operator support matrix:

Method/OperatorxConnectIAsyncQueryableNotes
.Where()YesYes
.Any()YesYes
.ToArray()YesYes
.ToList()YesYes
.Count()YesYes
.OrderBy()YesYes
.OrderByDescending()YesYes
.ThenBy()YesYes
.ThenByDescending()YesYes
.Skip()YesYesSee Paginating xConnect search results.
.Take()YesYesSee Paginating xConnect search results.
.FirstOrDefault()YesYes
.First()YesYes
.Single()YesYes
.SingleOrDefault()YesYes
== and !=YesYes
< and >YesYes
<= and >=YesYes
&& and ||YesYes
.GetBatchEnumerator()YesNo
.GetBatchEnumeratorSync()YesNo
.ToSearchResults()YesNo
.WithExpandOptions()YesNo
.AsEnumerable()YesNoSynchronous only.
ContainsNoYes
StartsWithNoYes
EndsWithNoYes
ToStringNoYes
EqualsNoYes
Note

There is no Like() extension method.

xConnect search provider limitations

xConnect search providers do not support the following scenarios:

Limitations of xConnect search providers:

  • Scenario: Limitation

  • Custom methods inside search expressions: The xConnect Client API does not support custom method calls inside LINQ query expressions. You receive a Sitecore.XConnect.Search.YourLinqIsTooStrongException or an XdbModelException exception.

  • Search for null values: It is not possible to check if a facet is null. For example:

    var notWebVisits = client.Interactions.Where(c => c.WebVisit() == null);
  • Search by Timespan in custom event properties: The following query (using a custom Timespan property) is unsupported

    can still use the default Duration property on events. This restriction only applies to events, not facets.

    var interactions = await _client.Contacts.Where(c => c.Interactions.Any(i => i.Events.OfType<CampaignEvent>().Any(e => e.CustomCampaignTimespan == TimeSpan.Zero)));
  • First, FirstOrDefault, Last, LastOrDefault, or Count inside a LINQ expression: Not supported:

    // First() inside a LINQ expression is unsupported:
    var interactions = await _client.Interactions.Where(i => i.Events.First().EngagementValue == 11).ToList();
    
    // FirstOrDefault() inside a LINQ expression is unsupported:
    var contacts = await _client.Contacts.Where(contact => contact.Interactions.OrderByDescending(x => x.StartDateTime).FirstOrDefault().WebVisit().SiteName == "value");
    
    // Last() inside a LINQ expression is unsupported:
    var contacts = await _client.Contacts.Where(contact => contact.Interactions.Last().WebVisit().SiteName == value);
  • Timespan: You cannot use Timespan with a query that combines the OfType operator AND a Timespan property (for example, Hours, Minutes, Seconds, and so on).Supported

    supported:

    events.OfType<SomeEventType>(e => e.SomeTypeTimeSpanField > TimeSpan.FromHours(2))
    events.OfType<SomeEventType>(e => e.SomeTypeTimeSpanField.Hours > 10)
  • Repeated names in paths to complex lists: The following queries are unsupported because Path.To.Nested is the same for both lists:

    i.Scores().Scores.Any(s=>s.Path.To.Nested.Any())
    i.ProfileScores().ProfileScores.Any(s=>s.Path.To.Nested.Any())
If you have suggestions for improving this article, let us know!