locked
How can I parse a Linq query?

    Question

  • Hi,

       I need to parse the Linq (.Net Framework 4) command in my system and it must be done at runtime. My desire is get the Linq as string and transform it in an actual code. As example, in my system I need to create a report, this is a runtime procedure, and the user selects the fields and has a "Where" selection. She types:

      From s in Database
      Where City contains "AB" && Country == "USA"
      Select City, Zip, Name

      The code above is typed in a text editor. Now the system must parse it and send the result to the report creator.

      How can it done?

      Thanks,

      Marco Castro

    Thursday, April 01, 2010 3:22 AM

Answers

  • Hello Marco,

     

    Glad to see you again!

     

    This question is very interesting.   If you want the user to input some LINQ query like we do in LINQPad, we may need .NET CodeDOM to help us compile and run the LINQ query during runtime.    For some sample codes, I would recommend you the sample VBCodeDOM in All-In-One Code Framework, which is an open-source project owned by MSDN support team.  

     

    Besides, you can also consider letting the user just input some key information, like the filter in WHERE clause and the return result in SELECT clause.   If so, the Dynamic LINQ Library can help us to build the LINQ query. 

     

    In addition, Entity SQL is another choice if we let the user input some key information. 

     

    If you have any questions, please feel free to let me know.

     

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, April 01, 2010 1:33 PM

All replies

  • Hello Marco,

     

    Glad to see you again!

     

    This question is very interesting.   If you want the user to input some LINQ query like we do in LINQPad, we may need .NET CodeDOM to help us compile and run the LINQ query during runtime.    For some sample codes, I would recommend you the sample VBCodeDOM in All-In-One Code Framework, which is an open-source project owned by MSDN support team.  

     

    Besides, you can also consider letting the user just input some key information, like the filter in WHERE clause and the return result in SELECT clause.   If so, the Dynamic LINQ Library can help us to build the LINQ query. 

     

    In addition, Entity SQL is another choice if we let the user input some key information. 

     

    If you have any questions, please feel free to let me know.

     

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, April 01, 2010 1:33 PM
  • Hello Marco,

     

    How is the problem?  If you need any further assistance, please feel free to let me know.

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, April 08, 2010 1:14 AM
  • Hi Lingzhi,

      The data you sent me totally met my needs.

      Thanks,

      Marco Castro

    Monday, April 12, 2010 11:56 AM
  • Hi Lingzhi,

      The data you sent me totally met my needs.

      Thanks,

      Marco Castro


    I know it's a long time since the last post, but which part of Lingzhi's post did you end up using?
    Friday, March 04, 2011 4:46 PM
  • It's really long time.   :) 

    Do you encounter any similiar issues?  If so, could you please open a new thread and let me know the thread link?  I will do my best to help.

    Have a nice weekend!

    Thanks


    Michael Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Saturday, March 05, 2011 2:38 AM
  • Hi Michael,

      I didn't noticed your last posts, sorry. To tell you the truth, I ended up with none of the solutions. I'm stuck in the development of the new application. There are so many options that it is difficult to decide which one to use. In the future I'll use the runtime compiler so the user can create a Linq query in runtime and send it's data to a report. This is my desire.

      Thank you very much for your keeping help.

      Marco Castro

    Wednesday, May 18, 2011 2:08 PM