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.
Source: stackoverflow.com
Related Query
- How to fix "The collection to which the Single aggregate is applied must be empty or contain exactly one item" InvalidOperationException?
- How to count the number of code lines in a C# solution, without comments and empty lines, and other redundant stuff, etc?
- If I have a collection of classes how can I return a collection of a single attribute of all the classes?
- How to write aggregate query in LINQ reusing part of the select code
- How to fix this "already an open DataReader associated with this Command which must be closed first" in my Linq-statement?
- How to get the whole record from a collection which has latest dateTime using linq?
- How to fix the following code so that it is ordered?
- I am having trouble with the code below. It is saying 'results' is an expression type '?'. which is not a collection type
- How to perform .Max() on a property of all objects in a collection and return the object with maximum value
- How can I get the index of an item in a list in a single step?
- How can I get LINQ to return the object which has the max value for a given property?
- How do I find the text within a div in the source of a web page using C#
- How do I get the latest date from a collection of objects using LINQ?
- How to use async within a lambda which returns a collection
- Linq: How to query items from a collection until the sum reaches a certain value
- How to assign empty string if the value is null in linq query?
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- How to update a single column in LINQ without loading the entire row?
- How can I get LINQ to return the index of the object which has the max value in a collection?
- How to get the next 12 months with empty months
- How does linq actually execute the code to retrieve data from the data source?
- How to find duplicates in a List<T> quickly, and update the original collection
- How to filter the Application.OpenForms collection with Linq?
- Web API, OData, EF5, Union: The 'Distinct' operation cannot be applied to the collection ResultType of the specified argument
- how to denormalize a collection which contains a collection using Linq
- C# Code Contracts -- How to ensure that a collection of items contains items with unique properties?
- Removing a single item from an enumerable source when the items are equal
- How can I write the following code more elegantly using LINQ query syntax?
- How to use MongoDB C# Driver Aggregate to get the latest item with specific values on 2 fields?
- Linq Groupby categorizes but how do I manipulate the values in the collection
More Query from same tag
- Find the difference between two nested dictionaries
- Determining the Linq to SQL Connection User Account
- How do I combine two array into cohesive objects using Linq?
- Error, method not supported by LINQ to Entities
- Merging two Lists and a dictionary to create a single dictionary
- How to use Linq objects to validate a view in MVC 2
- Overload for LINQ List.Contains() to accept column name
- LINQ expression behaves differently on literals?
- Converting dynamic row into column in linq
- Using LINQ to split items within a list
- Where Linq Method returning elements that don't satisfy condition
- NHibernate.Linq - Custom/Calculated property expression
- Eager loading and navigation properties
- linq : find values in list exist in another list or not?
- Using a linq or lambda expression in C# return a collection plus a single value
- Filter By Date in a GroupBy
- Linq Extension Methods and Error Handling
- List<object>.Contains Expression Tree
- group child records by parentid and sum the amount linq C#
- Reason not to use LINQ
- LINQ - Strip non-distinct rows from a table
- Populating a AutoCompleteBox with a list of anonymous types
- Help Linqifying collection to Dictionary
- LINQ query that searches for tuples
- anonymous type object or dynamic
- Get subtree from Nested Set Model Tree with Linq
- How to filter a list based on another list using Linq?
- Selecting duplicates items with NHibernate IQueryOver
- Linq - Retrieve first list after SelectMany
- How to group a list so that a single record for a day on a DateTime field is retrived using Linq?