Answer the question
In order to leave comments, you need to log in
How to call Any method under DbSet?
I'm trying to call the Any method using Expression, but an exception is thrown, tell me with the right solution?
var joinExpressionParmater = Expression.Parameter(filterRule.Instance, suffix + "1");
var prop = Expression.Property(joinExpressionParmater, filterRule.ConditionField);
var joinExpressionBody = Expression.Equal(
prop,
ToConstantExpressionOfType(TryCastFieldValueType(filter.Value, AllowTypes[filter.Type]), AllowTypes[filter.Type]));
var joinExpression = Expression.Lambda(joinExpressionBody, joinExpressionParmater);
var compiledMethod = DbContextSetMethod.MakeGenericMethod(filterRule.Instance);
var dbSet = compiledMethod.Invoke(Context, null);
var call = Expression.Call(
CollectionAny2.MakeGenericMethod(filterRule.Instance), Expression.Parameter(dbSet.GetType(), dbSet.GetType().Name), joinExpression);
Context.Contacs.Where(c => Context.ContactIdentifiers.Any(ci => ci.ContactId == c.Id && ci.phone = "1"))
Answer the question
In order to leave comments, you need to log in
In the exception, as a rule, there is an error, it is desirable to display it, so that it would be clearer.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question