This is a migrated thread and some comments may be shown as answers.
OrderBy non-persistent property
2 Answers 22 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Damien
Top achievements
Rank 1
Damien asked on 20 Jul 2012, 05:00 AM
Hi,

I'm getting an InvalidOperationException when sorting a LINQ query.
Is it possible to sort a LINQ query on a non-persistent property ?

For example:
In the Data Model:
public partial class Customer{   public string NonPersistentProperty { get { ... } }}

In my LINQ code:
Customers.OrderBy(c => c.NonPersistentProperty).ToList();

Thank you.

Damien.

2 Answers, 1 is accepted

Sort by
0
Accepted
Alexander
Telerik team
answered on 24 Jul 2012, 10:30 AM
Hello Damien,

OpenAccess always tries to translate as much as possible from the Linq query to SQL statements and execute them on the database server. The problem in this case is that the model has no information about the non-persistent property (whether it is mapped to a column or is calculated, etc.) and OpenAccess is unable to push the sorting to the server. This means that the sorting should be performed on the client side (in memory).
To achieve this you could slightly change the query and call OrderBy after ToList:
Customers.ToList().OrderBy(c => c.NonPersistentProperty);
Hope that helps.

Regards,
Alexander
the Telerik team
OpenAccess ORM Q2'12 Now Available! Get your hands on all the new stuff.
0
Damien
Top achievements
Rank 1
answered on 24 Jul 2012, 02:40 PM
So simple ;-)
It works perfect.

Thank you !
Tags
LINQ (LINQ specific questions)
Asked by
Damien
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Damien
Top achievements
Rank 1
Share this question
or