Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The LINQ expression node type 'Invoke' is not supported in LINQ to Entities

I'm trying to implement a 'IN' clause in my EF query through a lambda expression as follows:

        /*lambda expression to evaluate: status in[a, b, c...n]*/
        _IN myIN = (allStatus, status) =>
        {
            bool lambdaResult = false;
            foreach (int s in statuses)
            {
                if (status == s)
                {
                    lambdaResult = true;
                    break;
                }
            }
            return lambdaResult;
        };

        result = (from v in _entity.CAVouchers
                  join vs in _entity.CAVoucherStatus.Where(vs => (myIN(statuses, vs.VoucherStatusId) == true)) on v.VoucherStatusId equals vs.VoucherStatusId
                  join vsr in _entity.CAVoucherStatusReason on v.VoucherStatusReasonId equals vsr.VoucherStatusReasonid
                  where v.CyberAgent.CAID == caid                       
                  select new ACPVoucher() 
                  {
                      ...
                  }).ToList();

This is throwing a "The LINQ expression node type 'Invoke' is not supported in LINQ to Entities" error due to the "where" condition. Basically what I need is a "where statusId in [1, 2, 3]" kind of clause.

What is failing?...any tips on how to do this? The same approach is working for me when applied to a generic list.

Thanks

like image 685
allendehl Avatar asked Jan 30 '26 05:01

allendehl


1 Answers

You could just do a contains query:

where statuses.Contains(vs.VoucherStatusId)
like image 124
BrokenGlass Avatar answered Jan 31 '26 19:01

BrokenGlass