This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I am getting a NotSupportedException when I try to execute the following LINQ: var query2 = (from pl in uow.Locations What is wrong with the LINQ that is not supported? This is the exception: System.NotSupportedException was unhandled by user code |
|
|
Oddly enough a similar query works just fine: var query = (from pl in uow.Locations |
|
|
I tried re-writing the query above (which works) the way I originally did it with EF like below, but it fails with an exception: var query = from pl in uow.Locations Mindscape.LightSpeed.LightSpeedException was unhandled by user code |
|
|
The issue with the query is the part highlighted in bold: var query2 = (from pl in uow.Locations You are asking to order the projection. We dont support this. Instead you should perform the ordering within the query prior to the projection, or you could .ToList() to force enumeration and then perform the ordering client side. e.g. var query2 = (from pl in uow.Locations orderby pl.Area or: var query2 = (from pl in uow.Locations
Jeremy |
|
|
We dont support ordering by specific parts of a grouping key - you can order by the key itself which will expand to its appropriate parts but not by individual parts of the key are you are trying to perform in the query. e.g. var query = from pl in uow.Locations to: var query = from pl in uow.Locations
Jeremy |
|
|
Perfect, thank you! As it turns out, the reason I had the separate OrderBy() clauses in there after the distinct clause, was due to a bug I ran into with OpenAccess in that the ordering got dropped from the query when I had it in the LINQ query. I totally forgot about that, but your version works nicely. The grouping version is a direct translation from what we used to do in ADO.NET code, and is what I use in Entity Framework. But since I got the first version going using .Distinct(), it produces cleaner SQL than doing the grouping. |
|