Hi,
Probably this Stackoverflow thread can help you, at least I think you are looking for this...
Excerpt from the thread:
you could implement your own WhereIn method :
public static IQueryable<TEntity> WhereIn<TEntity, TValue>
(
this ObjectQuery<TEntity> query,
Expression<Func<TEntity, TValue>> selector,
IEnumerable<TValue> collection
)
{
if (selector == null) throw new ArgumentNullException("selector");
if (collection == null) throw new ArgumentNullException("collection");
ParameterExpression p = selector.Parameters.Single();
if (!collection.Any()) return query;
IEnumerable<Expression> equals = collection.Select(value =>
(Expression)Expression.Equal(selector.Body,
Expression.Constant(value, typeof(TValue))));
Expression body = equals.Aggregate((accumulate, equal) =>
Expression.Or(accumulate, equal));
return query.Where(Expression.Lambda<Func<TEntity, bool>>(body, p));
}
Usage:
public static void Main(string[] args)
{
using (Context context = new Context())
{
//args contains arg.Arg
var arguments = context.Arguments.WhereIn(arg => arg.Arg, args);
}
}
Your example (untested): (and doing 2 queries :( )
public List<Content> GetTagArticles(String tagName)
{
var relationIds = db.TagRelation.Where(t => t.Tag.Name == tagName).Select(t=>t.Id).ToList();
var contents = db.Content.WhereIn(c => c.TagRelation.Id, relationIds>);
return contents.ToList();
}