Why would I want to use an ExpressionVisitor?

Why would I want to use an ExpressionVisitor?

There was a issue where on the database we had fields which contained 0 or 1 (numeric), and we wanted to use bools on the application.

The solution was to create a "Flag" object, which contained the 0 or 1 and had a conversion to bool.

We used it like a bool through all the application, but when we used it in a .Where() clause the EntityFramework complained that it is unable to call the conversion method.

So we used a expression visitor to change all property accesses like .Where(x => x.Property) to .Where(x => x.Property.Value == 1) just before sending the tree to EF.

猜你喜欢

转载自www.cnblogs.com/chucklu/p/11580266.html