0

假设我需要创建自定义表达式来使用IQueryable<x>and进行一些操作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);
4

1 回答 1

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; }
}
于 2015-07-28T10:07:46.473 回答