OrderBy non-persistent property

3 posts, 1 answers
  1. Damien
    Damien avatar
    2 posts
    Member since:
    Dec 2011

    Posted 20 Jul 2012 Link to this post

    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. Answer
    Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 24 Jul 2012 Link to this post

    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.
  3. DevCraft banner
  4. Damien
    Damien avatar
    2 posts
    Member since:
    Dec 2011

    Posted 24 Jul 2012 Link to this post

    So simple ;-)
    It works perfect.

    Thank you !
Back to Top