When trying to filter dynamic dbset with generated expression
var expression = new ExpressionBuilder.ExpressionBuilder(BaseQuery.ElementType,TreeData.Filter).Build<T>();
Logger.LogDebug("Expression builder generated expression:\n{0}", expression.ToString());
BaseQuery = BaseQuery.Where(expression);
return this;
Generated expression
expression.ToString()
"c => c.Sources.Any(s => (s.Name == \"Intelligent Cotton Mouse\"))"
When trying to execute BaseQuery i get following exception
System.InvalidOperationException: The LINQ expression 'DbSet<Source>
.Where(s => EF.Property<Nullable<Guid>>((EntityShaperExpression:
EntityType: Campaign
ValueBufferExpression:
(ProjectionBindingExpression: EmptyProjectionMember)
IsNullable: False
), "Id") != null && EF.Property<Nullable<Guid>>((EntityShaperExpression:
EntityType: Campaign
ValueBufferExpression:
(ProjectionBindingExpression: EmptyProjectionMember)
IsNullable: False
), "Id") == EF.Property<Nullable<Guid>>(s, "CampaignId"))
.Any(s => s.Name == "Intelligent Cotton Mouse")' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
If i try to manually insert generated expression to .where()
(BaseQuery as IQueryable<Campaign>).Where(c =>
c.Sources.Any(s => s.Name == "Intelligent Cotton Mouse"));
it works, and predicate successfully translating to sql. What could be the problem?