Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • John C Scott 473 posts 1183 karma points
    Jan 09, 2015 @ 11:32
    John C Scott
    0

    using linq in razor view for the relation service

    In this topic: /backoffice-extensions/nupickers/questionssuggestions/60250-How-does-relations-work

    This works:

     var relations = ApplicationContext.Services.RelationService.GetByParentId(CurrentPage.Id).

    but this does not

    var relations = ApplicationContext.Services.RelationService.GetByParentId(CurrentPage.Id).Where(r => r.RelationTypeId = 2);

    or maybe the slightly nicer:

    var relations = ApplicationContext.Services.RelationService.GetByParentId(CurrentPage.Id).Where(r => r.RelationType.Alias = "x2y");
    It does work in a C# class, but in a razor view the error I get is :

    Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type

    I have no idea at all what this means and google isn't really helping me. It just seems to be telling me that what I am trying to do is "bad" as apparently it couldn't be unit tested. I don't really understand, and would appreciate some guidance.

    This is the whole error message:

    Compiler Error Message: CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
    Source Error:

     
    Line 3:  @{
    Line 4:      Layout = null;
    Line 5:      var relations = ApplicationContext.Services.RelationService.GetByParentId(CurrentPage.Id).Where(r => r.RelationTypeId = 2);


    Source File: c:\inetpub\v7test\Views\x.cshtml    Line: 5 


     

Please Sign in or register to post replies

Write your reply to:

Draft