Dynamic Search Query in LINQ

4 posts, 1 answers
  1. richardFlow
    richardFlow avatar
    62 posts
    Member since:
    Jun 2012

    Posted 17 Feb 2009 Link to this post

    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.

     

     

     

  2. Dimitar Kapitanov
    Admin
    Dimitar Kapitanov avatar
    632 posts

    Posted 17 Feb 2009 Link to this post

    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.
  3. DevCraft banner
  4. richardFlow
    richardFlow avatar
    62 posts
    Member since:
    Jun 2012

    Posted 17 Feb 2009 Link to this post

    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.
  5. Answer
    Dimitar Kapitanov
    Admin
    Dimitar Kapitanov avatar
    632 posts

    Posted 17 Feb 2009 Link to this post

    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.
Back to Top