A
A
Alexey2020-04-30 11:10:54
ASP.NET
Alexey, 2020-04-30 11:10:54

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);


in general i need to get this expression
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

1 answer(s)
V
Vladimir Korotenko, 2020-04-30
@firedragon

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 question

Ask a Question

731 491 924 answers to any question