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

Dynamic Search Query in LINQ

3 Answers 181 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.
richardFlow
Top achievements
Rank 1
richardFlow asked on 17 Feb 2009, 01:34 PM
Hi,

I'm trying to build a dynamic search query that adds where clauses to a LINQ query dependant on user input.   The code looks like so:

 

 

 

IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope();

scope.Transaction.Begin();

 

 

 

var query = from x in scope.Extent<SalesPrice>()

select x;

 

 

 

if (SkuUid != null)

 

{

query =

 

 

from q in query

where q.SkuUid == SkuUid

select q;

}

 

 

 

if (SalesType != null)

{

query =

 

 

from q in query

where q.SalesType == SalesType

select q;

}

 

 

 

 

 

Unfortunately upon running it i get the following error:

Second Where not implemented: value(Telerik.OpenAccess.Query.ExtentQuery`1[SalesPrice]).Select(x => x).Where(q => (Convert(q.SkuUid) = value(SalesPrice+<>c__DisplayClass4).SkuUid)).Where(q => (Convert(q.SalesType) = Convert(value(SalesPrice+<>c__DisplayClass4).SalesType)))

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NotSupportedException: Second Where not implemented: value(Telerik.OpenAccess.Query.ExtentQuery`1[SalesPrice]).Select(x => x).Where(q => (Convert(q.SkuUid) = value(SalesPrice+<>c__DisplayClass4).SkuUid)).Where(q => (Convert(q.SalesType) = Convert(value(SalesPrice+<>c__DisplayClass4).SalesType)))

Source Error:

Line 414:            if (SalesType != null)
Line 415:            {
Line 416: query = from q in query
Line 417: where q.SalesType == SalesType Line 418: select q;


Is this an error in your OpenAccess code?

Regards,

Richard.

 

 

 

3 Answers, 1 is accepted

Sort by
0
Dimitar Kapitanov
Telerik team
answered on 17 Feb 2009, 01:41 PM
Hi Web Belief Ltd,
Yes presently multiple where clauses are not implemented in our LINQ support. They will be available starting from Q1 2009 release scheduled for early March. Until then we advise you to use "AND" operators instead if possible. Hope that helps.

Regards,
Dimitar Kapitanov
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
richardFlow
Top achievements
Rank 1
answered on 17 Feb 2009, 01:54 PM
Thanks for swift response.

Can you clarify how this would work, or could you suggest a temporary workaround in OQL or the like until Q1 is released?

Regards,

Richard.
0
Accepted
Dimitar Kapitanov
Telerik team
answered on 17 Feb 2009, 02:46 PM
Hello Web Belief Ltd,
Well it will just work as expected having multiple where clauses used. I already suggested that you can use "AND" instead of the multiple where clauses. Let me clarify a bit by showing you a modified piece of the query:
if (SkuUid != null
  
if(SalesType != null
 query = from q in query 
 where q.SkuUid == SkuUid and q.SalesType == SalesType 
 select q; 
else 
 query = 
  from q in query 
 where q.SkuUid == SkuUid 
 select q; 


Greetings,
Dimitar Kapitanov
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.
Tags
LINQ (LINQ specific questions)
Asked by
richardFlow
Top achievements
Rank 1
Answers by
Dimitar Kapitanov
Telerik team
richardFlow
Top achievements
Rank 1
Share this question
or