0

usually when you write a Linq-to-Entity query against a list of attributes, you do this:

var attributes = new List<string>();
...
var result = dbContext.TableA.Where(e => attributes.Contains(e.FieldA));

But how to do this if you have an object with two or more attributes that need to match one row in the database?

class ClassA_DTO
{
  public string AttributeA;
  public string AttributeB;
}
...
var attributes = new List<ClassA_DTO>(); //comes from a JSON web API
...
// e.FieldA needs to match attributes.AttributeA
// AND e.FieldB needs to match attributes.AttributeB
var result = dbContext.TableA.Where(e => ???
Dee J. Doena
  • 1,631
  • 3
  • 16
  • 26

1 Answers1

0
var result = dbContext.TableA.Where(e => attributes.Select(a => a.AttributeA).Contains(e.FieldA) && attributes.Select(a => a.AttributeB).Contains(e.FieldB));

Using logical gates are possible.

sshanzel
  • 379
  • 5
  • 18