I have the following LINQ query that I am using to construct a structure to stuff into a JavaScript grid library which is irrelevant for this example, but I figured I would stil
The SingleOrDefault
call will throw an exception if the expression returns more than one item. Maybe you could try and use FirstOrDefault
if its just the Top 1 you want.
use the DataContext.Log property to display the sql generated by your query. You most likely have a sub-query that is generating more than one result when only one result is valid. For example the following sql will fail if more than one result is returned in the sub-query:
Select * from orders where customer_id =
(select customer_id from customer where name ='bob')
The equality of the where clause in the main query makes no sense if there is more than one result returned from the sub-query.
You may need to alter the uniqueness of some columns of data in your storage in order to ensure that only one row is returned in the sub-query. Another alternative is to alter your class so that the specific problem property being assigned to is a collection instead of a single value.