How do I just LINQ Join() to link two IQueryables? -
i have 2 iqueryables:
ingredient:
ingid description
availableingredient:
ingid
i have iqueryable ingredient:
var ingquery = in context.ingredients select i;
how can add join filters availableingredient
(i.e. inner join)? know how if had join time, i.e. from... join context.available... etc), join conditional, need use other syntax:
if (filterbyavailable) { iqueryable<available> availablequery = getavailableingredientquery(context); ingquery = ingquery.join(...); // can use join query? }
this may not right method, want do:
- getavailableingredientquery returns available ingredients query, i.e. 3000 of 6000 (but doesn't enumerate results yet it's returned iqueryable ef)
- join availablequery ingquery, there's inner join between 2 queries
edit:
this code i'm using (very fast), means duplicated code:
iqueryable<ingredient> query; if (filterbyavailable) { iqueryable<available> availablequery = getavailableingredientquery(context); query = item in context.ingredients // quite few `where` clauses , stuff join t in availablequery on item.ingid equals t.ingid select item; } else { query = item in context.ingredients // same `where` clauses , stuff above select item; }
use first query source of subsequent query.
iqueryable<ingredient> query = item in context.ingredients // quite few `where` clauses , stuff select item; if (filterbyavailable) { iqueryable<available> availablequery = getavailableingredientquery(context); query = item in query join t in availablequery on item.ingid equals t.ingid select item; }
Comments
Post a Comment