0

I found this question's accepted answer very informative to use Expressions with Linq to Entities. I can't figure out the VB.NET syntax, however.

Given something like (this part being in C# is fine)

public class MyCSClass 
{
    public static Expression<Func<unit, bool>> IsSomeStatus()
    {
        return u => u.IDStatus == (int)Enums.UnitStatus.SomeStatus;
    }
}

How do I put this expression in VB.NET like I would in C# like:

db.units.Any(MyCSClass.IsSomeStatus());

VB.NET doesn't recognize the type when I do either:

db.units.Where(MyCSClass.IsSomeStatus())

(Value of type 'Expression(Of Func(Of unit, Boolean))' cannot be converted to 'Func(Of unit, Boolean)')

or

db.units.Where(Function(u) MyCSClass.IsSomeStatus())

(Value of type 'Expression(Of Func(Of unit, Boolean))' cannot be converted to 'Boolean')

braX
  • 11,506
  • 5
  • 20
  • 33
MPelletier
  • 16,256
  • 15
  • 86
  • 137
  • I was unable to reproduce this - are you entierly sure that your db.units is actually an *IQueryable* and not a regular *IEnumerable*; Related fiddle https://dotnetfiddle.net/M2K04x with more or less equivalent VB code – user6144226 Jan 17 '18 at 22:52
  • If you ever need to transform Expression into its delegate form just call .Compile() – user6144226 Jan 17 '18 at 23:07

0 Answers0