我有一个实体类
public class BookPage {
public int PageIndex { get; set; }
}
然后我有一个表达:
Expression<Func<int, bool>> pageIndexCondition = idx => idx == 1;
和我想要的表达:
Expression<Func<BookPage, bool>> pageCondition = bookPage => bookPage.PageIndex == 1;
问题:如何使用pageIndexCondition
LINQ-to-SQL 查询,或者如何转换pageIndexCondition
为pageCondition
?
编辑:另一个不太优雅但仍符合我要求的解决方案是:
Expression<Func<T, bool>> GetPageIndexCondition(Expression<Func<T, int>> selector) {
return (T item) => selector(item) < 10; // This won't work because selector is Expression, so how to implement this correctly?
}
...
var pageCondition = GetPageIndexCondition(page => page.PageIndex);