dynamic LINQ cannot join?

4 posts, 0 answers
  1. Hessner
    Hessner avatar
    189 posts
    Member since:
    Mar 2003

    Posted 13 Nov 2009 Link to this post

    Hi,

    I am using this:

    using System.Linq.Dynamic; 

    and have included the file: Dynamic.cs into my project.
    (Visit this link, please)

    This code will compile and work out fine:

    var result = os.Extent<UserRole>().Where(condition1 + condition2).Select("new (User.UserID)");  


    This will compile, but return a runtime error:

    var query = (from u in Os.Extent<User>()  
    join u1 in Os.Extent<UserRole>().Where(wherePart) on u.UserID equals u1.UserID  
    join r in Os.Extent<Role>().Where(roles) on u1.RoleID equals r.RoleID  
    orderby u.FuldeNavn.ToLower()  
    select new  
    {  
    id = u.UserID,  
    u.Email,  
    Navn = u.FuldeNavn,  
    Rolle = r.Beskrivelse  
    }  
    ).Distinct(); 

    Stack trace:

    [ArgumentOutOfRangeException: Expression not bound to an extent.  
    Parameter name: ex  
    Actual value was UserRoleExtent.Where( => (1 = 1)).]  
       Telerik.OpenAccess.Query.QueryContext.FindExtent(Expression ex) +380  
       Telerik.OpenAccess.Query.QueryContext.CheckJoin(MethodCallExpression mce) +96  
       Telerik.OpenAccess.Query.QueryContext.CreatedQuery(IQueryable created, IQueryable prev) +771  
       Telerik.OpenAccess.ExtentQuery`1.System.Linq.IQueryProvider.CreateQuery(Expression expression) +139  
       System.Linq.Queryable.Join(IQueryable`1 outer, IEnumerable`1 inner, Expression`1 outerKeySelector, Expression`1 innerKeySelector, Expression`1 resultSelector) +516  
       Jeresforening.ui.admin.hovedmenu.Nyhedsbrev.ModtagerRolle_SelectedIndexChanged(Object sender, EventArgs e) in C:\inetpub\Jeresforening.dk\ui\admin\hovedmenu\Nyhedsbrev.aspx.cs:256  
       Jeresforening.ui.admin.hovedmenu.Nyhedsbrev.ModtagerGrid_NeedDataSource(Object source, GridNeedDataSourceEventArgs e) in C:\inetpub\Jeresforening.dk\ui\admin\hovedmenu\Nyhedsbrev.aspx.cs:205  
       Telerik.Web.UI.RadGrid.OnNeedDataSource(GridNeedDataSourceEventArgs e) +113  
       Telerik.Web.UI.RadGrid.ObtainDataSource(GridRebindReason rebindReason, Boolean IsBoundUsingDataSourceId) +49  
       Telerik.Web.UI.RadGrid.AutoDataBind(GridRebindReason rebindReason) +87  
       Telerik.Web.UI.RadGrid.Rebind() +10  
       Jeresforening.ui.admin.hovedmenu.Nyhedsbrev.OnLoad(EventArgs e) in C:\inetpub\Jeresforening.dk\ui\admin\hovedmenu\Nyhedsbrev.aspx.cs:55  
       System.Web.UI.Control.LoadRecursive() +50  
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627  
     

    In exampel 1(the good) and in 2(the bad) my "Where part" consist of pure sql text, it is not any kind lamda syntax. But in exampel 2, when joining, "pure text" dosent seem to be allowed/expected? 


  2. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 18 Nov 2009 Link to this post

    Hi Bo,

    we have identified and fixed some issues with this kind of queries. The next release will contain the necessary patches. (Due within a few days). Thanks for reporting this to us.
    One thing I don't understand though is that you mention SQL text; this is not possible as all the strings that you pass into a dynamic Where() clause will be translated to their respective Expression tree form. Or am I missing something?

    All the best,
    Thomas
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
  4. Hessner
    Hessner avatar
    189 posts
    Member since:
    Mar 2003

    Posted 18 Nov 2009 Link to this post

    Hi Thomas,

    Looking forward to the fix.

    And you are right, its not SQL - it's text like this:

    "UserId == 123" 

    But not like this:

     

    "c => c.UserId == 123"

     

    Thanks for the update of my telerik points ;-)

    Regards,
    Bo Hessner

  5. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 18 Nov 2009 Link to this post

    Hello Bo,

    you are welcome!

    Greetings,
    Thomas
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top