0

Let's say I need create custom expression to make some manipulation with IQueryable<x> and IQueryable<y>. Regretfully I do not have idea how to implement this. This is my try:

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;
        }

Or say other words I need result like this:

IQueryable <somevalue> x = query.CustomJoinExtension(Iqueryablevalue);
andrey.shedko
  • 3,128
  • 10
  • 61
  • 121

1 Answers1

1

Something like this:

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; }
}
Davor Zlotrg
  • 6,020
  • 2
  • 33
  • 51
  • if this is for use in the Entity Framework, the class restriction should have "class" added, otherwise EF cannot understand the query: http://stackoverflow.com/a/21172754/1117815 – felipe Dec 22 '16 at 14:28