Help with Linq and Generics. Using GetValue inside a Query

前端 未结 2 1348
小蘑菇
小蘑菇 2020-12-03 16:34

I\'m triying to make a function that add a \'where\' clause to a query based in a property and a value. This is a very simplefied version of my function.

Pri         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-03 16:59

    Have you tried pulling out the DirectCast and reflecting on the lambda parameter instead? Something like this:

    query.Where(Function(c) _
        c.GetType().GetProperty(p, GetType("Int64")).GetValue(c, Nothing) = PValue)
    

    I'm not certain you can even do this sort of thing in a lambda, but it's worth a shot.

提交回复
热议问题