You can create an expression tree if you declare it as such.
But is it possible to get an expression tree for a regular piece of code, such as a method or getter property?
What I'm trying to do, say, for an order processing system, I have a class for order elements:
class Item : Entity { [Cascade] public Document document { get; set; } public int line { get; set; } public Product product { get; set; } public string description { get; set; } public decimal qty { get; set; } public decimal price { get; set; } public decimal net { get { return qty * price; } } public VatCode vat_code { get; set; } }
where the network value is qty * price, so I would like to declare it as such, either using a property or method, and then also have a structure that parses this expression so that it can generate the appropriate SQL to determine the corresponding calculated column in the corresponding base view data.
The most obvious way to do this is to get an expression tree for the getter property or method, but I cannot find any directions on how to do this or what is possible. (I found a way to get the body of the method as a stream of bytes, but this is not what is needed here.)
If this is not possible, I suggest that the recommended solution would be to declare something like a static field, which is an expression tree, and compile / run it at run time for internal use, and also inherit as usual for SQL generation
source share