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