【发布时间】:2014-06-09 11:53:44
【问题描述】:
我正在为现有工具编写IQueryable 实现。此工具的一个非常常见的功能是类似于 Exists at the database 的查询。为了支持这一点,我想用如下方法扩展IQueryable:
public static IQueryable<T> WhereExists<T, U>(
this IQueryable<T> Current,
IQueryable<U> Other,
Func<T, Field> CurrentSelector) where U : Entity
{
return WhereExists(Current, Other, x => x.ID, CurrentSelector);
}
public static IQueryable<T> WhereExists<T, U>(
this IQueryable<T> Current,
IQueryable<U> Other,
Func<U, Field> RemoteSelector,
Func<T, Field> CurrentSelector) where U : Entity
{
throw new NotImplementedException(
"This method is only implemented for db-backed queries.");
}
扩展方法的存在让我可以绕过编译器,真正的功能将在表达式访问者中。
问题是我希望它出现在表达式中,但它会一直运行到扩展方法。是否有必须遵循的限制才能将其放入表达式中(例如使用 .Where 等)?
【问题讨论】:
标签: c# expression iqueryable