Search code examples
c#entity-frameworkequality

How do I use "or" (|) operator in C# "object.equals"


var controllingContext = _context.Inventaris.Include(i => i.Artkl).Include(i => i.Status).Where(x => x.StatusId.Equals(stat[0] | stat[1]));

I am trying to add an or operator in C# to the object.equals method this was working while I didn't have the or operator in there and it was just checking for 1 item but now I added the or operator and it doesn't work anymore. Any help would be greatly appreciated


Solution

  • If I understood correctly, you want to filter StatusId equals stat[0] or stat[1]. If so you just need to use OR(||) operator as following:

    .Where(x => x.StatusId.Equals(stat[0]) || x.StatusId.Equals(stat[1]));
    

    See LINQ Filtering