This is a migrated thread and some comments may be shown as answers.

dynamic LINQ cannot join?

3 Answers 209 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Hessner
Top achievements
Rank 2
Hessner asked on 13 Nov 2009, 08:16 PM
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? 


3 Answers, 1 is accepted

Sort by
0
Thomas
Telerik team
answered on 18 Nov 2009, 01:00 PM
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.
0
Hessner
Top achievements
Rank 2
answered on 18 Nov 2009, 04:27 PM

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

0
Thomas
Telerik team
answered on 18 Nov 2009, 05:16 PM
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.
Tags
LINQ (LINQ specific questions)
Asked by
Hessner
Top achievements
Rank 2
Answers by
Thomas
Telerik team
Hessner
Top achievements
Rank 2
Share this question
or