none
Modifying a LINQ Query on the Fly

    Question

  • Greetings Everyone, 

    I am somewhat new to using LINQ to query data rather than SQL Queries.   I'm trying to figure out if there is an easy way to programatically build a LINQ query at run time.   Specifically if I was using SQL, since the command is a string I could easily add or modify a cmd before running it as doing somehting like

    String cmdstr = "Select a.a, a.b from tblABC"; 

    if( limit = true) cmdstr += " where a.c = " & someVar;  

    ...

    then run the query.  No problem.   But I do not see an obvious way that I could do something similar with LINQ.   

    your input in much apperciated.

    Thank You,

    John

     

    Wednesday, February 27, 2013 5:16 PM

Answers

All replies

  • Hi John;

    To your question, "I'm trying to figure out if there is an easy way to programatically build a LINQ query at run time.", one way this may be done is to use the Dynamic LINQ (Part 1: Using the LINQ Dynamic Query Library). Please see the link where it describes how to use the library and where it can be downloaded.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Wednesday, February 27, 2013 8:52 PM
  • Thanks Fernando.   I'm this infomraiton is extremely helpful.   I'm surprised the .NET team hasn't just build LINQ.Dynamic into the .NET library.  Maybe they will in 5.0. 
    Wednesday, February 27, 2013 11:45 PM