Error in lambda expression in LoadWith FetchStrategy

2 posts, 0 answers
  1. itzik
    itzik avatar
    2 posts
    Member since:
    Jan 2009

    Posted 18 Jun 2012 Link to this post

    I tried to order link table with fetch strategy and got exception:

    Telerik.OpenAccess.FetchOptimization.FetchStrategy fetchStrategy = new Telerik.OpenAccess.FetchOptimization.FetchStrategy();
    fetchStrategy.LoadWith<Project>(p => p.Matrices.OrderBy(x => x.Position));            
    dbContext.FetchStrategy = fetchStrategy;

    exception:
    Invalid FetchStrategy path expression, must be property/field access on persistent types or Select() on persistent collections.
    Parameter name: expression
    Actual value was p.Matrices.OrderBy(x => x.Position).

    please advice

    Thanks
  2. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 19 Jun 2012 Link to this post

    Hello itzik,

    This syntax is not allowed - the LoadWith method is meant to be used only in order to specify a navigation property (referenced object or collection), which should be loaded together with the root object in a single SQL query. Any additional operations are not expected.
    If you would like to specify an order for the objects retrieved from the database, you should do that in the linq query executed against the context class of your domain model.

    Greetings,
    Alexander
    the Telerik team
    OpenAccess ORM Q2'12 Now Available! Get your hands on all the new stuff.
  3. DevCraft banner
Back to Top