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

Dynamic LINQ

5 Answers 205 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 14 Mar 2009, 08:26 AM
var wherePart = "q.SkuUid == SkuUid and q.SalesType == SalesType";   
 
var getIt from q in query    
where wherePart    
select q;    
 

Is dynamic LINQ, like the above, included in Q1 2009?

5 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 17 Mar 2009, 11:38 AM
Hi Bo Hessner,

dynamic LINQ is supported, but the example given by you must be slightly rewritten:

 var getIt = scope.Extent<Bo>()
.Where("SkuUid == @SkuUid and SalesType == @SalesType", 1234, 5678);

So the entire query cannot be made up by string concatenation, but string pieces must be given along with the parameters in the right order.
You might want to check this link also : Dynamic LINQ .

Kind regards,
Alexander
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Zoran
Telerik team
answered on 17 Mar 2009, 01:06 PM
Hi Hessner,

There was a little misunderstanding in our last letter to you. The format of the dynamic Linq query should be slightly different:

 var getIt = scope.Extent<Bo>()
.Where("SkuUid == @0 and SalesType == @1", 1234, 5678);

The thing is that named parameters are not supported at the moment with OpenAccess and numbed parameters should be used instead.

Again we are sorry for the inconvenience.


All the best,
Zoran
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Hessner
Top achievements
Rank 2
answered on 17 Mar 2009, 01:39 PM
Regarding:

 var getIt = scope.Extent<Bo>()
.Where("SkuUid == @SkuUid and SalesType == @SalesType", 1234, 5678);

My real "where part" contain fields from several tables, how is this done?
var getIt = scope.Extent<table1 Join table2 Join table3 >?
.Where("table1.SkuUid == @SkuUid and table2.SalesType == @SalesType", 1234, 5678);
0
Accepted
Zoran
Telerik team
answered on 17 Mar 2009, 02:19 PM
Hello Hessner,

You should just point the references in the where clause like in the sample bellow which is based on the
Northwind database.

var result = scope.Extent<Order>() 
        .Where("Customer.CustomerID == @0 and Employee.EmployeeID==@1 ""ALFKI",1); 
 


All the best,
Zoran
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Hessner
Top achievements
Rank 2
answered on 17 Mar 2009, 10:25 PM
I got it - this work out fine:

var condition = string.Format("PortalID == {0}", Utilities.CurrentPortalid());  
var result = os.Extent<UserRole>().Where(condition).Select("new (User.UserID, User.Email, User.FuldeNavn, Medlemsnummer, Role.RoleName, SidsteLogon)");  
RadGrid1.DataSource = result;  
 
Tags
LINQ (LINQ specific questions)
Asked by
Hessner
Top achievements
Rank 2
Answers by
Alexander
Telerik team
Zoran
Telerik team
Hessner
Top achievements
Rank 2
Share this question
or