none
What is Expression Trees and its objective or usage RRS feed

  • Question

  • i never use Expression Trees. please tell me what is Expression Trees and when people use it?

    tell me few scenario when people need to go for Expression Trees.

    i read this post https://www.codeproject.com/Articles/235860/Expression-Tree-Basics

    i do not understand code objective when i see Expression tree related code

    Expression Trees always work with func delegate Func ?

    it seems when we need to pass something at runtime to linq or EF then Expression Trees is required.

    please help me to understand what is Expression Trees

    why one should care Expression Trees with few good examples.

    thanks

    Thursday, December 21, 2017 10:09 AM

Answers

  • Hi Sudip_inn,

    >>i never use Expression Trees. please tell me what is Expression Trees and when people use it?

    An expression tree provides a method of translating executable code into data. This can be very valuable if you want to modify or transform code before executing it. In particular, it can be useful if you want to transform C# code such as a LINQ query expression into code that operates on another process, such as a SQL database.

    For example, if we want to write a dynamic LINQ where clause, we could use Expression Trees to achieve it.

    >>Expression Trees always work with func delegate Func ?

    Yes.

    >>why one should care Expression Trees with few good examples.

    The following blogs provide some simple demo about Expression Tree.

    https://blogs.msdn.microsoft.com/charlie/2008/01/31/expression-tree-basics/

    The following document provide a complete sample code about dynamic where clause, which use Expression Trees.

    https://www.codeproject.com/Tips/582450/Build-Where-Clause-Dynamically-in-Linq

    Best regards,

    Zhanglong Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 22, 2017 3:09 AM
    Moderator

All replies

  • Hi Sudip_inn,

    >>i never use Expression Trees. please tell me what is Expression Trees and when people use it?

    An expression tree provides a method of translating executable code into data. This can be very valuable if you want to modify or transform code before executing it. In particular, it can be useful if you want to transform C# code such as a LINQ query expression into code that operates on another process, such as a SQL database.

    For example, if we want to write a dynamic LINQ where clause, we could use Expression Trees to achieve it.

    >>Expression Trees always work with func delegate Func ?

    Yes.

    >>why one should care Expression Trees with few good examples.

    The following blogs provide some simple demo about Expression Tree.

    https://blogs.msdn.microsoft.com/charlie/2008/01/31/expression-tree-basics/

    The following document provide a complete sample code about dynamic where clause, which use Expression Trees.

    https://www.codeproject.com/Tips/582450/Build-Where-Clause-Dynamically-in-Linq

    Best regards,

    Zhanglong Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 22, 2017 3:09 AM
    Moderator
  • can u plzz write a easy and nice example code on expression tree for beginner.
    Thursday, January 4, 2018 12:08 PM