我可以将什么类型传递给 Where 子句?
What Type can I pass to a Where clause?
我想将表达式存储在一个变量中,然后将其传递给 linq 语句中的 Where 子句,但我似乎无法弄清楚 Type
我需要使用什么。我想要达到的结果是:
var expression = x => x.UserId == 5;
var result = db.Table.Where(expression);
我知道存储在 Table
中的实体的 Type
在某处是必需的,但不知道在哪里。
Expression<Func<Foo, bool>> expression = x => x.UserId == 5;
(用 Table
中实体的实际类型替换 Foo
当然...)
我想将表达式存储在一个变量中,然后将其传递给 linq 语句中的 Where 子句,但我似乎无法弄清楚 Type
我需要使用什么。我想要达到的结果是:
var expression = x => x.UserId == 5;
var result = db.Table.Where(expression);
我知道存储在 Table
中的实体的 Type
在某处是必需的,但不知道在哪里。
Expression<Func<Foo, bool>> expression = x => x.UserId == 5;
(用 Table
中实体的实际类型替换 Foo
当然...)