Where clause not working with parantheses

▼魔方 西西 提交于 2019-12-12 02:27:09

问题


Suppose the following Query using a NH 3.4 and RepositoryPattern

var list = _repository
     .QueryOver()
     .Where(x => (x.Age > 20))  // notice the parantheses
     .Future()
     .ToList();

Whith these parantheses added the NH is failing to work, and causes a SO exception.

If replacing .Where(x => (x.Age > 20)) with .Where(x => x.Age > 20) it works as expected.

Any clues on why it doesn't work with extra parantheses?

Note

This is a simplified scenario from the bigger picture. In production i'm passing that .Where(...) through a parameter Expression<Func<Person, bool>> where


回答1:


I have a doubt the error is there:

Expression<Func<MyClass, bool>> mc1 = x => (x.ID > 20);
Expression<Func<MyClass, bool>> mc2 = x => x.ID > 20;

var body1 = mc1.Body.NodeType; // GreatThan
var body2 = mc2.Body.NodeType; // GreatThan

The brackets are removed by the compiler. There is nothing in the Expression tree "language" (class system) to explicitly represent a bracket.



来源:https://stackoverflow.com/questions/30274155/where-clause-not-working-with-parantheses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!