score:1

The Select part in your query instantiates a persistent object, which implies that each element in the result sequence is unique (a persistent object cannot be loaded twice into the same Session). That is why the query is translated into a Single aggregate function. The cause of the error is that matching of the innerKey and outerKey in the Join expression may produce duplicated entries of items selected from the outer sequence.  

If duplicates are not expected in your scenario, then you need to fix data in your database or rewrite the query to take this into account. For instance, you can use the "join into" operator to group duplicated records:

from t in new XPQuery<Core.Model.Task.Task>(session, true)
   join ols in new XPQuery<OrderLineSpecification>(session, true)
   on t.PickSpecification equals ols.PickSpecification
   into tg
   where tg.key == task.PickSpecification
      && tg.Any(gi.Status != TaskStatuses.Cancelled && olsesUsedForTaskCompletion.Contains(ols.Oid))
   select t

Replacing sequences in the query may also help to avoid the error in some scenarios, but you will have duplicated object references in the result sequence then:

from ols in new XPQuery<OrderLineSpecification>(session, true)
   join t in new XPQuery<Core.Model.Task.Task>(session, true)
   on ols.PickSpecification equals t.PickSpecification
   where ols.PickSpecification == task.PickSpecification
      && t.Status != TaskStatuses.Cancelled
      && olsesUsedForTaskCompletion.Contains(ols.Oid)
   select t

If you are fine with duplicated records in the result sequence, I suggest that you simply add a projection to the Select statement, so that the query does not need to instantiate persistent objects.

from t in new XPQuery<Core.Model.Task.Task>(session, true)
   join ols in new XPQuery<OrderLineSpecification>(session, true)
   on t.PickSpecification equals ols.PickSpecification
   where t.PickSpecification == task.PickSpecification
      && t.Status != TaskStatuses.Cancelled
      && olsesUsedForTaskCompletion.Contains(ols.Oid)
   select new { SomeProperty = t.SomeProperty, AnotherProperty = t.AnotherProperty }

PS: If none of above works in your particular case, contact DevExpress Support Service directly. Your question is too specific to XPO, so you will likely obtain the qualified answer there.


Related Query

More Query from same tag