假设我需要创建自定义表达式来对IQueryable<x>
和IQueryable<y>
进行一些操作。遗憾的是,我不知道如何实现这一点。这是我的尝试:
public static IQueryable<T> JoinQueries<T>(this IQueryable<T> query, IQueryable<T> expr)
{
if (query == null)
throw new ArgumentNullException("query");
//Here we make Join for x and and return result something like this:
query = from a in query join b in expr on a.Id equals b.Id select a;
return query;
}
或者说其他话我需要这样的结果:
IQueryable <somevalue> x = query.CustomJoinExtension(Iqueryablevalue);
答案 0 :(得分:1)
这样的事情:
public static IQueryable<T> JoinQueries<T>
(this IQueryable<T> query, IQueryable<T> expr) where T : IHasId
{
if (query == null)
throw new ArgumentNullException("query");
//Here we make Join for x and and return result something like this:
query = from a in query join b in expr on a.Id equals b.Id select a;
return query;
}
public interface IHasId
{
int Id { get; set; }
}