Is there a particular reason LinqKit's expander can't pick up Expressions from fields?

前端 未结 2 1684
谎友^
谎友^ 2020-12-23 14:59

I\'m using LinqKit library which allows combining expressions on the fly.

This is a pure bliss for writing Entity Framewok data acess layer because several express

2条回答
  •  失恋的感觉
    2020-12-23 15:12

    I created improved version of Mic answer:

    if (input == null)
        return input;
    
    var field = input.Member as FieldInfo;
    var prope = input.Member as PropertyInfo;
    if ((field != null && field.FieldType.IsSubclassOf(typeof(Expression))) ||
        (prope != null && prope.PropertyType.IsSubclassOf(typeof(Expression))))
        return Visit(Expression.Lambda>(input).Compile()());
    
    return input;
    

    Main advantage is removal DynamicInvoke that have big overhead and calling Invoke only when I really need it.

提交回复
热议问题