-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
For example, the following fails:
_ = ctx.Projects.Where(b => new List<int> { 1, b.Int }.Where(b => b > 1).Contains(2)).ToList();... whereas the following works:
_ = ctx.Projects.Where(b => new[] { 1, b.Int }.Where(b => b > 1).Contains(2)).ToList();First, QueryRootProcessor.VisitQueryRootCandidate recognizes NewArrayExpression (inline array) and converts it to InlineQueryRootExpression; but it does not do so for an inline List, and possibly other IList collection types.
Then, in QueryableMethodNormalizingEV, we identify List.Contains and convert it to Queryable.Contains (code):
var ids = new List<int> { 1, 2 };
_ = ctx.Blogs.Where(b => ids.Contains(b.Id)).ToList();This is important for recognizing the Contains as a queryable operator later, etc.
However, we specifically exclude this normalization when the instance is a NewExpression or MemberInitExpression:
_ = ctx.Blogs.Where(b => new List<int> { 1, 2 }.Contains(b.Id)).ToList();That means that Contains is processed as enumerable rather than queryable, ending up in ContainsTranslator (which we eventually want to remove).
I'm not sure why we made these specific exclusions, any idea @maumar?